if (url==what_i_want) ..............

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
apollovega
Forum Newbie
Posts: 12
Joined: Thu Feb 19, 2004 3:34 pm

if (url==what_i_want) ..............

Post by apollovega »

Is there a way to have it so

Code: Select all

<?
if (url == what_i_want)
     include("blah.php");
else
     include("black.php");

?>
basically is there a way to have it so when the brower says "http://www.somesite.com/someplace.php?page=somewhere" it'll execute a certain script. Any possible way?

Thanks for reading this :-D

P.s, don't bother running the code, it's just to explain it better since I have yet to improve my explaining skills. Thanks again.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

if(!empty($_GET['page'])) {
require_once $_GET['page'].'.php';
} else {
require_once 'default.php';
}

You might also want to add some checking to make sure the file exists and that they don't/can't enter stuff like ?page=../../../../etc/passwd for example (though adding the .php on the end sorta stops anything useful, but still best to check paths).
apollovega
Forum Newbie
Posts: 12
Joined: Thu Feb 19, 2004 3:34 pm

Post by apollovega »

I see, thanks dood! :-) I'll try it out when I get a chance. Any chance of another way? Thanks a bunch :-)
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

markl999's way is the best _approach_
Post Reply