Results 1 to 4 of 4

Thread: PHP Includes

  1. #1
    Join Date
    Sep 2006
    Location
    Doncaster, UK
    Posts
    4,081
    Tokens
    0

    Latest Awards:

    Default PHP Includes

    I want to use PHP includes as a means of navigation on my site so like;

    www.habboer.com/index.php?page=home

    takes me to the homepage and whatever 'home' is changed to, it takes you there - if there's no page then take to an error404 page.

    I have a navigation box which I want the... well... navigation in and I have a content box where I want different content in depending upon the 'home' attribute.

    Can anyone make me a secure code for this, thanks
    Quote Originally Posted by Nain View Post
    i voted 'Not Sure' as im, not sure!

  2. #2
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    Something like this should do the trick:
    PHP Code:
    <?php

    if(isset($_GET["page"]))
    {

        
    $page $_GET["page"];
        
        
    // Clean the variable to prevent exploitation
        
    $clean = array("http""www"".");
        
        
    $page str_replace($clean""$page);

        
    // Add the extension
        
    $page $page.".php";
        
        if(
    file_exists($page))
        {

            include(
    $page);
        
        }
        else
        {

            include(
    "404.php");

        }
    }
    else
    {

        include(
    "home.php");

    }

    ?>

  3. #3
    Join Date
    Apr 2005
    Posts
    4,614
    Tokens
    1,290

    Latest Awards:

    Default

    edit; simon beat me, didnt refresh thread (a)

  4. #4
    Join Date
    Sep 2006
    Location
    Doncaster, UK
    Posts
    4,081
    Tokens
    0

    Latest Awards:

    Default

    Simoné +Rep, if that means anything nowadays.
    Quote Originally Posted by Nain View Post
    i voted 'Not Sure' as im, not sure!

Posting Permissions

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