PDA

View Full Version : index.php?page=whatever- Link problems


kazuki
09-10-2002, 09:08 AM
I'm using a basic navigation setup where I use a page to an index page to navigate to other pages (eg. index.php?page=whatever) where appending the .php extension does give the code an element of protection. Clicking a link of<a href="index.php?page=whatever"> works fine but in my case it adds contents of the original index.php file and not replacing them. I got lot of other problems. When I open the default page (index.php)I get a error notice and I can't figure out how.

Notice: Undefined index: page in C:\PROGRAM FILES\BADBLUE\PE\dual\series.php on line 32

Here's the script

<?
$page = $_GET["page"]; // ????
if (isset($_GET['page']))
if ($page != "") {
include_once("".$page.".php");
} else {
include_once("index.php");
}
?>


Another thing a user tries to get to a deleted or non-existant page by changing the values/text in the location bar of their browser (whatever.php?page=??), I want to redirect to a default page, instead of showing an error - which also shows the file I'm using to list my URLs in.

A good example is here http://www.webarama.com.au/webnews.php?ser=21 - where if you add/change the ser=21 in the url, it takes you to a blank page, instead of showing a PHP error message.
Another was when I type http://www.webarama.com.au/webnews.php, it shows its original contents of displaying its links like eg.
News 1 (url = http://www.webarama.com.au/webnews.php?ser=21)
News 2 (url = http://www.webarama.com.au/webnews.php?ser=22)
News 3 (url = http://www.webarama.com.au/webnews.php?ser=23) and so on


******************************************************************************

layout of webnews.php = contents of webnews.php (links here)

by clicking the link of http://www.webarama.com.au/webnews.php?ser=21

would be:

layout of webnews.php = contents of "ser=21" (new contents)


******************************************************************************


Clicking on the links would change the entire contents of the original to a new one and
I can't figure out how to do it. This is one the main reasons I wanted to learn PHP, but there is very little documentation like this one about something so simple. I don't have any idea if I'm doing it right.
Is there an even better way to use an index?page=whatever setup for navigation? I'd appreciate
suggestions of solving the problem.

Ökii
09-10-2002, 10:51 AM
<?php
$page = $_GET['page'];
if(!isset($page) || $page=="") {$page='index';}
// if a value hasn't been attributed to $page set it to default to index
if(!file_exists($page.'.php')) {$page='pagenotfound';}
// sniff for the included page and use pagenotfound.php if it's not there.
include($page.'.php');
?>

Personally I'd add a hardcoded path to the includes folder
... include('../includes/'.$page.'.php'); etc