March 13, 201016 yr Hello. I would like to make my web pages URL's to be like "http://www.example.com/index.php?page=example" Instead of "http://www.example.com/index.html". How would I do that? Ive tried searching, but I haven't had any luck.
March 13, 201016 yr Hello. I would like to make my web pages URL's to be like "http://www.example.com/index.php?page=example" 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
March 13, 201016 yr To go directly to page replace '//Do Code' above with: header("Location: "/index.html"); exit();
March 13, 201016 yr To go directly to page replace '//Do Code' above with: 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.
March 13, 201016 yr 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. Hmm, you may be right.
March 14, 201016 yr 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. 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>";?>
Create an account or sign in to comment