index.php?page=
#1
Posted 13 March 2010 - 02:11 AM
Instead of "http://www.example.com/index.html".
How would I do that? Ive tried searching, but I haven't had any luck.
#2
Posted 13 March 2010 - 02:51 AM
Kix, on 13 March 2010 - 02:11 AM, said:
Instead of "http://www.example.com/index.html".
How would I do that? Ive tried searching, but I haven't had any luck.
Create a get variable first
<?php
$url = $_GET['page'];
//Check to see if url equals to a certain value
if($url === 'example'){
//Do code
}
//Write the url like this
echo "<a href='index.php?page=example'>Link</a>";
?>
If this helped please +1 me if u dont mind
#3
Posted 13 March 2010 - 08:25 AM
header("Location: "/index.html");
exit();
#5
Posted 13 March 2010 - 12:30 PM
TopShopper, on 13 March 2010 - 08:25 AM, said:
header("Location: "/index.html");
exit(); I don't think this is what the OP was getting at. This code simply redirects to the page stated in the code, it doesn't retrieve the content from a database which to me seems like the only reason you would use a url like example.com?page=example
webdesigner93 is on the right track, but where it says //do code, I would be more inclined to suggest pulling the relevant content from a database. That way, one php page controls the output for all the pages on the website.
#6
Posted 13 March 2010 - 01:46 PM
notbanksy, on 13 March 2010 - 12:30 PM, said:
webdesigner93 is on the right track, but where it says //do code, I would be more inclined to suggest pulling the relevant content from a database. That way, one php page controls the output for all the pages on the website.
Hmm, you may be right.
#7
Posted 14 March 2010 - 11:38 AM
webdesigner93, on 13 March 2010 - 02:51 AM, said:
<?php
$url = $_GET['page'];
//Check to see if url equals to a certain value
if($url === 'example'){
//Do code
}
//Write the url like this
echo "<a href='index.php?page=example'>Link</a>";
?>
If this helped please +1 me if u dont mind
Ouch
What happens if you have 'allow_url-fopen' turned on? An attacker you open files on your server.
You shoudl really be doing one of a few things.
- get the value of $url against an array of allowed values
- use a simple swicth statement
- You could also use a regex to stop an attacker traversin directories (see below)
$UEL = preg_replace('/\W/si', '', $_GET['page']);
The above would filter something like http://www.evilsite.com to httpevilsitecom.
#8
Posted 14 March 2010 - 11:40 AM
notbanksy, on 13 March 2010 - 12:30 PM, said:
webdesigner93 is on the right track, but where it says //do code, I would be more inclined to suggest pulling the relevant content from a database. That way, one php page controls the output for all the pages on the website.
Tep definately.
Simply redirecting to another page remves all the benefits of such an url structure (E.g. easier site updating, keeping content in single files, make site wide changes easily etc.).
#9
Posted 14 March 2010 - 01:30 PM
rallport, on 14 March 2010 - 11:38 AM, said:
What happens if you have 'allow_url-fopen' turned on? An attacker you open files on your server.
You shoudl really be doing one of a few things.
- get the value of $url against an array of allowed values
- use a simple swicth statement
- You could also use a regex to stop an attacker traversin directories (see below)
$UEL = preg_replace('/\W/si', '', $_GET['page']);
The above would filter something like http://www.evilsite.com to httpevilsitecom.
Ok well heres an updated and more secure way then
$url = $_GET['page'];
$allowed_values = array('example','example2'.'example3');
//Check to see if url equals to a certain value
if(in_array($url,$allowed_values){
if($url === 'example')
{
//Do code
}
}else{
echo "<p>The action you have performed is invalid!</p>";
}
//Write the url like this
echo "<a href='index.php?page=example'>Link</a>";?>
- ← can you update a sql table continuously?
- Server Side (PHP, Databases, ASP.NET, etc)
- PHP Search page Problem →
Help


















