/index.php?page=

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Asnom
Forum Newbie
Posts: 1
Joined: Fri Mar 21, 2008 11:19 am

/index.php?page=

Post 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 ^^.
hayson1991
Forum Newbie
Posts: 14
Joined: Thu Mar 20, 2008 1:19 pm

Re: /index.php?page=

Post 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']);
 
?>
 
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: /index.php?page=

Post 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;
}
 
Post Reply