Page 1 of 1
/index.php?page=
Posted: Fri Mar 21, 2008 11:47 am
by Asnom
I've searched and searched, but no matter where i look i can't find an answer. How do i make it so that i can go to /index.php?page= and get the page. I am sorry if this is really beginner, but i cannot find an answer. Thank you for your time ^^.
Re: /index.php?page=
Posted: Fri Mar 21, 2008 2:14 pm
by hayson1991
Asnom wrote:I've searched and searched, but no matter where i look i can't find an answer. How do i make it so that i can go to /index.php?page= and get the page. I am sorry if this is really beginner, but i cannot find an answer. Thank you for your time ^^.
Use this as your index.php if you want the url to stay as /index.php?page=
Code: Select all
<?php
include $_GET['page'].'.php';
?>
Use this as your index.php if you want the url to be redirected to the page
Code: Select all
<?php
header('Location: '.$_GET['page']);
?>
Re: /index.php?page=
Posted: Fri Mar 21, 2008 2:27 pm
by andym01480
Although the previous post answers the question. Using include on user entered stuff is pretty dangerous!
Using a switch statement to check the page variable and then acting on expected entries and having a default to cover people being naughty is safer.
Code: Select all
<?php
switch ($_REQUEST['page'])
{
case 1:
include("page1.php");
break;
case 2:
include("page2.php");
break;
case 3:
include("page3.php");
break;
default:
include("page1.php");
break;
}