Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 5 12345 LastLast
Results 1 to 10 of 47
  1. #1
    Join Date
    Aug 2004
    Location
    Over there. ^_^
    Posts
    1,100
    Tokens
    0

    Latest Awards:

    Lightbulb [PHP] PHP includes instead of Iframes

    PHP includes are sometimes used instead of iframes it makes another page appear as though it is actually on the page similar to iframes without all of the scrollbars right making a php include is pretty basic
    PHP Code:
    <?php
    include ('yourpage.php');
    ?>
    rite to make the include change without having to make loads of the same page is a bit more complicated
    were you want your include to appear put this code
    PHP Code:
    <?php
    $_GET
    ['page'];  
    switch(
    $page)
    {
    case 
    "home":
    include(
    'home.php');
    break;
    case 
    "news":
    include(
    'news.php');
    break;
    case 
    "tutorials":
    include(
    'tutorials.php');
    break;
    case 
    "contact":
    include(
    'contact.php');
    break;
    case 
    "sitemap":
    include(
    'sitemap.php');
    break;
    case 
    "admin":
    include(
    'admin.php');
    break;
    default:
    include(
    'home.php');
    break;
    }
    ?>
    you can change all of the
    PHP Code:
    case "admin":
    include(
    'admin.php');
    break; 
    to the directory of the pages you want and you can also change the name (next to 'case' )
    and what you want the default page to be
    PHP Code:
    default:
    include(
    'home.php');
    break; 
    now to make the links which will change the include use this:
    HTML Code:
    <a href="index.php?page=home">Home</a>
    this would change the include to the page with the 'case' called home
    to see an example of this www.xenigma.co.uk

    *** Updated ***

    I have discovered a new way to use php includes were you do not have to add
    PHP Code:
    case "admin":
    include(
    'admin.php');
    break; 
    everytime to use a new page, the code:
    PHP Code:
    <?php
    if (!isset($page))
    {
    include(
    "pages/home.php");

    if(
    file_exists($_GET['page'].".php")){
        include 
    $_GET['page'].'.php';    
    }
    if(
    file_exists($_GET['page'].".html")){
        include 
    $_GET['page'].'.html';
    }
    if(
    file_exists($_GET['page'].".txt")){
        include 
    $_GET['page'].'.txt';
    }
    elseif (isset(
    $page) && !@include("$page"))
                 {
                 echo 
    "Error Page not found!";
         } 
    ?>
    now the code broken down and the meanings

    PHP Code:
    <?php
    starts the php script

    PHP Code:
    if (!isset($page))
    {
    include(
    "pages/home.php");

    this part sets what the starting page will be example look at the www.xenigma.co.uk index page there is a description of what was used to develop the site and who it is owned by this is the starting page

    PHP Code:
    if(file_exists($_GET['page'].".php")){
        include 
    $_GET['page'].'.php';    
    }
    if(
    file_exists($_GET['page'].".html")){
        include 
    $_GET['page'].'.html';
    }
    if(
    file_exists($_GET['page'].".txt")){
        include 
    $_GET['page'].'.txt';

    this sets what file extensions can be used when searching for them

    PHP Code:
    elseif (isset($page) && !@include("$page"))
                 {
                 echo 
    "Error Page not found!";
         } 
    this is what message will be displayed if the page doesnt exist,

    PHP Code:
    ?> 
    this ends the php script. Now you can display any page were the include is, all as you need to do now is use the file name example in a link
    index.php?page=pages/contact/contact that would open in the include either

    pages/contact/contact.php
    or
    pages/contact/contact.html
    or
    pages/contact/contact.txt
    Last edited by xEnigmA; 03-08-2005 at 05:38 PM.
    *Image Removed


    Ahemm.. How exactly was my sig innapropriate?
    Goddamit i hate this forum :@
    I RESIGN FROM GRAPHICS DESIGNER :@ :@ :@

  2. #2
    Join Date
    Aug 2004
    Location
    UK
    Posts
    11,283
    Tokens
    2,031

    Latest Awards:

    Default

    I usealy prefer to use if statments.

    PLus for a lot of links its far easyer just to use a dinamic include system aka

    PHP Code:
    <?php
    $page 
    basename($page);

    if(!
    $page)
    include(
    "start.php");

    else
    if(
    file_exists("$page.php"))
    {
    include(
    "$page.php");
    }
    else
    {
    echo 
    "Error. Page not found";
    }

    ?>
    wich basicly just includes the value of the $page, with php on the end

    so

    index.php?page=cat

    would include the page cat.php

    and

    index.php?page=dog

    would include the page dog.php


    And if the page varilble isnt there aka just

    index.php?

    it will include start.php or any other page you add in the same place


    At the end of the script it aslo checks to see if the file exsists and if it doesnt it shows the error message.

    i prefer this method as it saves on codeing and makes it easyer to add pages
    Last edited by Mentor; 31-05-2005 at 01:50 PM.

  3. #3
    Join Date
    Aug 2004
    Location
    Over there. ^_^
    Posts
    1,100
    Tokens
    0

    Latest Awards:

    Talking

    i find that slightly more confusing mine was ment to be more basic :p
    *Image Removed


    Ahemm.. How exactly was my sig innapropriate?
    Goddamit i hate this forum :@
    I RESIGN FROM GRAPHICS DESIGNER :@ :@ :@

  4. #4
    Join Date
    Oct 2004
    Location
    Scotland
    Posts
    2,280
    Tokens
    1,075

    Latest Awards:

    Default

    i prefere the if stament also, its alot easier and quicker

    http://www.stupidian.com
    (contains mild swearing)

  5. #5
    Join Date
    Aug 2004
    Location
    Over there. ^_^
    Posts
    1,100
    Tokens
    0

    Latest Awards:

    Lightbulb

    explain to me how it works, and how i can configure it im quite new to php coding :p
    *Image Removed


    Ahemm.. How exactly was my sig innapropriate?
    Goddamit i hate this forum :@
    I RESIGN FROM GRAPHICS DESIGNER :@ :@ :@

  6. #6
    Join Date
    Aug 2004
    Location
    UK
    Posts
    11,283
    Tokens
    2,031

    Latest Awards:

    Default

    the if statment or the include system i did.

    if works same way as yorus aka
    PHP Code:
    <?php
    $_GET
    ['page'];  
    if(
    $page == "home")
    {
    include(
    'home.php');
    }
    elseif(
    $page == "news")
    {
    include(
    'news.php');
    }
    else
    {
    include(
    'home.php');
    }

    ?>
    For a short eg..

    My script works quite simply (info in comments / code hints)
    PHP Code:
    <?php
    $page 
    basename($page); // get page varibale form url

    if(!$page// if page varible doesnt exist
    include("start.php");  // include this

    else   / if not then do this
    if(file_exists("$page.php")) // does the file exists? if yes
    {
    include(
    "$page.php"); // do this. this incude includes the varible $page with the php exsntion added on
    //  so the page included is the varible plus the exntion. aka if page = cat it would include cat.php in to the page... if it existed
    }
    else  
    // if not
    {
    echo 
    "Error. Page not found"// show this error message
    }

    ?>

  7. #7
    Join Date
    Mar 2005
    Location
    Dog House
    Posts
    1,000
    Tokens
    0

    Latest Awards:

    Default

    ok i have done all of what u said but the page loads in a new window not were i want any ideas?

  8. #8
    Join Date
    Jul 2004
    Location
    Bournemouth. UK
    Posts
    3,638
    Tokens
    0

    Latest Awards:

    Default

    Did you put:

    PHP Code:
    <?php
    $_GET
    ['page'];  
    switch(
    $page)
    {
    case 
    "home":
    include(
    'home.php');
    break;
    case 
    "news":
    include(
    'news.php');
    break;
    case 
    "tutorials":
    include(
    'tutorials.php');
    break;
    case 
    "contact":
    include(
    'contact.php');
    break;
    case 
    "sitemap":
    include(
    'sitemap.php');
    break;
    case 
    "admin":
    include(
    'admin.php');
    break;
    default:
    include(
    'home.php');
    break;
    }
    ?>
    In the content box where you want it to appear?
    REMOVED

    Edited by jesus (Forum Super Moderator): Please do not have text in your signature which is over size 4.

  9. #9
    Join Date
    Mar 2005
    Location
    Dog House
    Posts
    1,000
    Tokens
    0

    Latest Awards:

    Default

    lmao no i put that in the nav area

  10. #10
    Join Date
    Jul 2004
    Location
    Bournemouth. UK
    Posts
    3,638
    Tokens
    0

    Latest Awards:

    Default

    Why? :S

Page 1 of 5 12345 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •