link help..

hey guys I was always wondering like how can I make http://www.domain.com/index.php?site=contact or http://www.domain.com/index.php?site=feedback or http://www.domain.com/index.php?site=myprofile how can I make that? lets say I have a php page named tools.php how would I make the page show to a user when he enters http://www.domain.com/index.php?site=tools ? please help guys! i would appreciate it! and what is the name of these kind of links?

$site=$_REQUEST[‘site’];
$site.=".php";
include $site;

or in 1 line
include $_REQUEST[‘site’].“php”;

While resago is technically correct, I would recommend a more secure way. The reason it is insecure is that it allows them to input any path they want, it can be a file that’s not even in your web directory, or even on your server.

What I would recommend is to create a “.php” file containing an array of all the sub-pages and their name, for example ‘$approved_list = Array( “contact”=>“contact.php”, “login”=>“login.php”)’ and you can include the file containing that array wherever you may need it. Then you would do…

if( in_array( $_GET[ 'site' ], $approved_list) ) {
   include( $approved_list [ $_GET[ 'site' ] ] );
} else {
   print 'No hacking for you.';
}

Additionally, this allows you to hide the true path of pages, for example if you have several sub-directories.

References:
http://us.php.net/manual/en/reserved.variables.php
http://us.php.net/manual/en/function.include.php
http://us.php.net/manual/en/function.in-array.php

Sponsor our Newsletter | Privacy Policy | Terms of Service