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!


Results 1 to 8 of 8

Thread: PHP Includes

  1. #1
    Join Date
    Mar 2009
    Location
    Western Australia
    Posts
    386
    Tokens
    0

    Default PHP Includes

    I finally figured it out and then I found out i need more help. I have this code but how can I make it so when index.php is opened it automatically shows home.php in where its placed, It currently does that but then every page that I open has that at the top.

    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!"
         }  
    ?>

  2. #2
    Join Date
    Oct 2006
    Posts
    2,918
    Tokens
    946
    Habbo
    Verrou

    Latest Awards:

    Default

    http://www.habboxforum.com/showthread.php?t=43037

    Search the forum before you post.
    Quote Originally Posted by Special-1k View Post
    How do you uninstall an internet? I want to uninstall my Google Chrome and
    get firefox but I never really got rid of an internet my dad usually did it for me.
    If you know how post below so I can do this.

  3. #3
    Join Date
    Mar 2009
    Location
    Western Australia
    Posts
    386
    Tokens
    0

    Default

    Yes but that doesn't solve my problem

  4. #4
    Join Date
    Apr 2009
    Location
    United Kingdom
    Posts
    1,111
    Tokens
    100

    Latest Awards:

    Default

    ummm

    You want to redirect index.php to home.php?

    header('Location:home.php');

    Put that on index.php right after <?php

  5. #5
    Join Date
    Mar 2009
    Location
    Western Australia
    Posts
    386
    Tokens
    0

    Default

    Quote Originally Posted by BoyBetterKnow View Post
    ummm

    You want to redirect index.php to home.php?

    header('Location:home.php');

    Put that on index.php right after <?php
    Tried it then and it doesn't work:
    Code:
    Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\jack1\index.php:27) in C:\xampp\htdocs\jack1\index.php on line 28

  6. #6
    Join Date
    Nov 2006
    Location
    Narrich
    Posts
    5,687
    Tokens
    0
    Habbo
    Jamesy...

    Latest Awards:

    Default

    you need to put it before the <head></head> tags
    Ex-janitor. Might pop in from time to time, otherwise you can grab all my information from http://jamesy.me.uk/

  7. #7
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    PHP Code:
    <?php 

    $page 
    $_GET['page'];
    $folder 'pages';
    $extension '.php';

    if( isset(
    $page) )
    {
        
    $pageInc $folder '/' $page $extension;
        if( 
    is_readable$pageInc ) )
        {
            include 
    $pageInc;
        }
        else
        {
            echo 
    'Page not found, sorry!';
            
    // or include a 404 page.
        
    }
    }
    else
    {
        include 
    $folder '/home.php';
    }
      
    ?>
    Really crude, but I think that's what you want. Just make sure you set the folder relative to the php file and the extension. This is only base code, it is important that you should check you want the user to open the requested page otherwise they can potentially request "../index" and caus a never-ending loop.

    However, give that a try.
    Last edited by Source; 04-10-2009 at 01:34 PM.

  8. #8
    Join Date
    Mar 2009
    Location
    Western Australia
    Posts
    386
    Tokens
    0

    Default

    thanks source, It works so now I can get on with my site.. +REP !

Posting Permissions

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