PDA

View Full Version : PHP Includes



redtom
22-01-2007, 05:31 PM
How do you use them? Because I've tryed and tryed but every time I click the link it goes to the index.php?page=about.php but the included page does not change. Can some one post on how to do it please.

Thanks,
Tom.

jarhead!
22-01-2007, 05:33 PM
<?php
include ('somthink.php');
?>

redtom
22-01-2007, 05:35 PM
<?php
include ('somthink.php');
?>

Yeah I can do that what I mean is I want to beable to change the include, when some one click a button in the nav.

F32
22-01-2007, 05:36 PM
www.php.net/includes

Invent
22-01-2007, 05:37 PM
<?php

$file = $_GET[page];

include("$file.php");

?>

Then have as your link: pagecodeison.php?page=home

Blah, I dont know lol.

YouFail
23-01-2007, 09:40 AM
Please ignore this post. I have edited it thus no infraction kthnxbi

primal
23-01-2007, 11:57 AM
<?php

$file = $_GET[page];

include("$file.php");

?>

Then have as your link: pagecodeison.php?page=home

Blah, I dont know lol.

Forgot the ['page'], but yeah, thatl work fine.

YouFail
23-01-2007, 12:44 PM
Thanks for posting butyou dont need the ['page']. It works fine without it...

primal
24-01-2007, 01:22 PM
Dang, it would seem you are correct. :P my mistake

Agnostic Bear
24-01-2007, 01:33 PM
<?php

$file = $_GET[page];

include("$file.php");

?>

Then have as your link: pagecodeison.php?page=home

Blah, I dont know lol.

Far too insecure, use something like this:



<?php
$url = $_GET["view"];
$site = ("http://url.tld/folder/"); // Write the full url to the folder that the file is in, without the trailing slash ( / )
$rofl = str_ireplace("../", "", $url); // Replace all ../ with nothing to stop naughty lil hacker wannabe ganster rappers.
if(isset($_GET["view"])) // if ?view=blah is set
{
if(file_exists("$rofl.php")) // if $rofl ($_GET["view"] - ../) exists
{
include("$site/$rofl.php"); // Include that file .php!
}
else
{ // If it doesn't exist.
include("404.php"); // Include the 404 page!
}
}
else // If it isn't set....
{
include("welcome.php"); // Include the welcome page
}
?>

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