I am wondering how people make sites that appears to have one document index.php and they navigate with index.php?page="somthing"
I would like to implement this in my own site but I don't know how
I am wondering how people make sites that appears to have one document index.php and they navigate with index.php?page="somthing"
I would like to implement this in my own site but I don't know how
Hey there,
This is what I use for all of my scripts:
//Global header so your site looks uniform.
if(isset($_GET['page'])){
$page = $_GET['page'];
}else{
$page = 'default';
}
switch ($page) {
/*This is where you define what goes in your page*/
case "something" :
include('something.php');
break;
/*Hey, Hey, doin the default!*/
case "default" :
echo("Welcome to my home page");
break;
}
//Global footer so your page can be swaddled by a common theme.
The first IF keeps you from getting an error if someone visits index.php without a value in the URL for page.
thanks,
json
His code is a good example of a way to do this, just please DON'T do something like:
if (isset($_GET['page'])) {
include($_GET['page']);
}
That's just stupid. Make sure you specify a selection of pages and an actual file, like his code does.
hi!
And this is my variant of the schwim code.
The $filename here is to be included in my Main Template body.
I added the POST option, just in case I need it
$pagdr = directory with pages, 'mypages/'
$startpage = 'index.htm'
$reqpg = requested page
$pagefile = the file
$pagename = title of page
404.htm = custom not found error page
<?php
$reqpg=isset($_GET['page'])? $_GET['page'] : $startpage;
$reqpg=isset($_POST['page'])? $_POST['page'] : $reqpg;
if(empty($reqpg))
$reqpg=$startpage;
$pagefile=$pagdr . $reqpg;
$pagename=$reqpg;
if(!is_file($pagefile)){
$pagefile=$pagdr . '404.htm';
$pagename='Not found';
}
?>