PDA

View Full Version : PHP Includes



Aflux
27-01-2008, 07:24 PM
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 :D

Invent
27-01-2008, 07:30 PM
Something like this should do the trick:


<?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");

}

?>

Robbie
27-01-2008, 07:31 PM
edit; simon beat me, didnt refresh thread (a)

Aflux
27-01-2008, 07:34 PM
Simoné <3 +Rep, if that means anything nowadays.

Want to hide these adverts? Register an account for free!