open inside current page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
OX 3
Forum Newbie
Posts: 22
Joined: Fri Jan 02, 2004 7:58 pm
Location: El Paso, TX

open inside current page

Post by OX 3 »

is there a PHP code that allows me to open a page inside a site that uses include tags and then the code for the main page and when you click a link it changes ???
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Something like this will do it...

Code: Select all

<?php

if(!isset($_GET["page"]))
{
    $page = "news";
}
else
{
    $page = $_GET["page"];
}

?>

<html>
<head>
</head>
<body>

<?php include($page.".php") ?>

<hr />

<a href="?page=news">News Page</a><br />
<a href="?page=biog">Biog Page</a>

</body>
</html>
If you click on "News Page" then a file called news.php will be loaded, if you click on "Biog Page" then a file called biog.php will be loaded.


It should work :)
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Code: Select all

else 
{ 
    $page = $_GET["page"]; 
}
makes xss attack possible. use [php_man]basename[/php_man]:

Code: Select all

else
{ 
    $page = basename($_GET["page"]); 
}
Post Reply