code help

coolv1994

Member
Messages
508
Reaction score
0
Points
16
does anyone know the code in php to stay on the same page but switch content
like index.php?id=page1 and that shows page 1 and index.php?id=page2 shows page 2
 

Christopher

Retired
Messages
14,659
Reaction score
8
Points
0
PHP:
<?php 

if (isset($_GET['id'])) $PAGE = $_GET['id'];

else $ID = 'home'; 

switch ($ID) {
//1- index
case 'home': 
include ('home.tpl.php'); 
break;

//2- something else
case 'home': 
include ('home.tpl.php'); 
break;

default:
echo "<p align=center>Error 404!<br><br>The page you request doesn't exist!</p>"; 
break;
} 

?>
Found that on some website a long time ago. Can't remember where though.
 
Last edited:

coolv1994

Member
Messages
508
Reaction score
0
Points
16
thanks =)
Edit:
the code didnt work
when i load the pag it says could not load directory in home/...
 
Last edited:

nabil

New Member
Messages
39
Reaction score
0
Points
0
Hello,
You can also use the following :
Code:
<?php 
if(!$_GET['id']) include('home.php');
if($_GET['id'] == 1) include('page1.php');
if($_GET['id'] == 2) include('page2.php');
?>

NaBiL
 
Top