Help me with my navigation script

Status
Not open for further replies.

Mitch

New Member
Messages
908
Reaction score
0
Points
0
I use this navigation script
<?php
$page = $_GET['page'];
if ( !empty($page) && file_exists('' . $page . '.php') && stristr( $page, '.' ) == False )
{
// pages = directory where you store your pages
$file = '' . $page . '.php';
}
else
{
// home.php = default page
$file = 'home.php';
}

include $file;
//
?>

Only the problem is when one page does not exist , it will show the default page.

Can some one make a error page when these pages does not exist
 

Mitch

New Member
Messages
908
Reaction score
0
Points
0
I tried that when you got to the index , you start with the error page
 

Livewire

Abuse Compliance Officer
Staff member
Messages
18,169
Reaction score
216
Points
63
Make this your code (lines in red are new)

Code:
			 				              <?php 
$page = $_GET['page'];
[COLOR=Red]if (empty($page)) {
$page = "index";
}[/COLOR]
if ( !empty($page) && file_exists('' . $page . '.php') && stristr( $page, '.' ) == False ) 
{
// pages = directory where you store your pages
   $file = '' . $page . '.php';
}
else
{
// home.php =  default page
   $file = 'home.php';
}
  
include $file;
// 
?>

Not the prettyest code but what it'll do is if $page is empty, it'll make it NOT empty. Really cheesy and theres probably a more elegant way to do it, but that'll make it so if $page is empty, it'll set it to whatever you want your index to be.

That should work because, in theory, the only time you won't tell it what page you want to be on is if someone loads the homepage (like yoursubdomain.x10hosting.com/ - doesn't define $page, so $page is empty, but they want the index).

Lemme know if it works; thats almost identical to something I'm running on my page, cept that second if-statement on mine doesn't exist cause I did it differently :)
 
Status
Not open for further replies.
Top