Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

index.php?page=

Featured Replies

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 :)

  • Author

Thank You both for helping.

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.

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.

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.