help using url formatting

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
scrupul0us
Forum Newbie
Posts: 2
Joined: Tue Aug 24, 2004 3:34 pm

help using url formatting

Post by scrupul0us »

i want to use url formatting like this:

index.php?page=pagename.htm

how do i pass "pagename.htm" to

include ("pagename.htm");
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

if your url looks like index.php?page=pagename.htm and you want to include pagename.htm do this

Code: Select all

include ($_GET['page']);
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

warning: blindly including a page is dangerous. make sure you filter the sent page to make sure it's one you want to be able to load..
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

how right you are feyd it would be a good idea to have an array of avaiable pages like this

Code: Select all

$array = array("blah.htm","somepage.htm","anypage.htm");
if (in_array($_GET['page'],$array)) include ($_GET['page']);
else echo "access denied";
scrupul0us
Forum Newbie
Posts: 2
Joined: Tue Aug 24, 2004 3:34 pm

Post by scrupul0us »

hrm... when i try:

/index.php?page=question.htm

where it should be included just comes up blank...

heres the code:

<?php
$array = array("support.htm","question.htm","contact.htm","question.htm");
if (in_array($_GET['page'],$array)) include ($_GET['page']);
else echo "access denied";
?>

should also add that this php page is in:

/wwwroot/

and the htm pages are in:

/wwwroot/htm
Post Reply