using an error page for index.php?page=xx

is there any way to make it so when someone types in something thats not there (i.e. index.php?page=a_wrong_page it just displays them an error page , this is what I have for my index.php page – but I still can gifure it out :frowning:)[/size] [code]<?php
//////////////// FOR IMAGES
if ( isset($_REQUEST[‘image’]) )
{
$image = $_REQUEST[‘image’];
}
if ( $image == ‘phpgroundbanner’ )
{
$image = “images/linkus/468x60phpground.png”;
$im = imagecreatefrompng($image);
$tc = ImageColorAllocate ($im, 255, 255, 255);
//$black = imagecolorallocate($im, 0, 0, 0);
//ImageString($im, 3, 2, 2, “bleh”, $black);
//ImageString($im, 2, 2, 15, “”, $black);
header(“Content-Type: image/png”);
Imagepng($im,’’,100);
ImageDestroy ($im);
}
if ( $image == ‘phpgroundbanner2’ )
{
$image = “images/linkus/468x60phpground2.png”;
$im = imagecreatefrompng($image);
$tc = ImageColorAllocate ($im, 255, 255, 255);
//$black = imagecolorallocate($im, 0, 0, 0);
//ImageString($im, 3, 2, 2, “bleh”, $black);
//ImageString($im, 2, 2, 15, “”, $black);
header(“Content-Type: image/png”);
Imagepng($im,’’,100);
ImageDestroy ($im);
}
if ( $image == ‘phpgroundbanner3’ )
{
$image = “images/linkus/468x60phpground3.png”;
$im = imagecreatefrompng($image);
$tc = ImageColorAllocate ($im, 255, 255, 255);
//$black = imagecolorallocate($im, 0, 0, 0);
//ImageString($im, 3, 2, 2, “bleh”, $black);
//ImageString($im, 2, 2, 15, “”, $black);
header(“Content-Type: image/png”);
Imagepng($im,’’,100);
ImageDestroy ($im);
}
////////
if ( $image == ‘phpgroundbutton’ )
{
$image = “images/linkus/88x31phpground.png”;
$im = imagecreatefrompng($image);
$tc = ImageColorAllocate ($im, 255, 255, 255);
//$black = imagecolorallocate($im, 0, 0, 0);
//ImageString($im, 3, 2, 2, “bleh”, $black);
//ImageString($im, 2, 2, 15, “”, $black);
header(“Content-Type: image/png”);
Imagepng($im,’’,100);
ImageDestroy ($im);
}
if ( $image == ‘phpgroundbutton2’ )
{
$image = “images/linkus/88x31phpground2.png”;
$im = imagecreatefrompng($image);
$tc = ImageColorAllocate ($im, 255, 255, 255);
//$black = imagecolorallocate($im, 0, 0, 0);
//ImageString($im, 3, 2, 2, “bleh”, $black);
//ImageString($im, 2, 2, 15, “”, $black);
header(“Content-Type: image/png”);
Imagepng($im,’’,100);
ImageDestroy ($im);
}
if ( $image == ‘phpgroundbutton3’ )
{
$image = “images/linkus/88x31phpground3.png”;
$im = imagecreatefrompng($image);
$tc = ImageColorAllocate ($im, 255, 255, 255);
//$black = imagecolorallocate($im, 0, 0, 0);
//ImageString($im, 3, 2, 2, “bleh”, $black);
//ImageString($im, 2, 2, 15, “”, $black);
header(“Content-Type: image/png”);
Imagepng($im,’’,100);
ImageDestroy ($im);
}
////////
if ( $image == ‘phpgroundsmallbutton’ )
{
$image = “images/linkus/88x15phpground.png”;
$im = imagecreatefrompng($image);
$tc = ImageColorAllocate ($im, 255, 255, 255);
//$black = imagecolorallocate($im, 0, 0, 0);
//ImageString($im, 3, 2, 2, “bleh”, $black);
//ImageString($im, 2, 2, 15, “”, $black);
header(“Content-Type: image/png”);
Imagepng($im,’’,100);
ImageDestroy ($im);
}
if ( $image == ‘phpgroundsmallbutton2’ )
{
$image = “images/linkus/88x15phpground2.png”;
$im = imagecreatefrompng($image);
$tc = ImageColorAllocate ($im, 255, 255, 255);
//$black = imagecolorallocate($im, 0, 0, 0);
//ImageString($im, 3, 2, 2, “bleh”, $black);
//ImageString($im, 2, 2, 15, “”, $black);
header(“Content-Type: image/png”);
Imagepng($im,’’,100);
ImageDestroy ($im);
}
if ( $image == ‘phpgroundsmallbutton3’ )
{
$image = “images/linkus/88x15phpground3.png”;
$im = imagecreatefrompng($image);
$tc = ImageColorAllocate ($im, 255, 255, 255);
//$black = imagecolorallocate($im, 0, 0, 0);
//ImageString($im, 3, 2, 2, “bleh”, $black);
//ImageString($im, 2, 2, 15, “”, $black);
header(“Content-Type: image/png”);
Imagepng($im,’’,100);
ImageDestroy ($im);
}
//////////////// END FOR IMAGES
include_once(“data/google/googlebot.php”);
///////// site man
if (isset($_GET[“page”])) {
$page = $_GET[“page”];
}
else {
$page = “index”;
}
if ($page == “”) {
//if(@!include “$page”)
$page = “error”;
}
//}
if (!isset($class_included)) {
include_once(“data/class.php”);
}
if (!isset($Siteman)) {
$Siteman = new Website(“1.1.8b”);
}
if ($do == “login”) {
if (isset($_POST[“username”]) && isset($_POST[“password”])) {
$Siteman->loginresult = $Siteman->login($_POST[“username”],$_POST[“password”]);
}
if (isset($_POST[“returnto”])) {
$Siteman->refresh(0,$_POST[“returnto”]);
}
}
else if ($do == “logout”) {
$Siteman->logout();
if (isset($_GET[“return”])) {
$Siteman->refresh(0,$_GET[“return”]);
}
}
$visits = file(“data/count.txt”);
$hits = count(file(“data/stats.txt”));
if ($page == “index”) {
$hits++;
}
$resetdate = date($short_dateformat,$visits[0]);
if ($do == “default”) {
$info = $Siteman->db_get(0,$page,“data/pages”);
$content = “pages/” . $page . “.php”;
$includewrappers = 0;
$title_bar = $info[4];
$page_title = $info[5];
$info[3]++;

	if (file_exists($content)) {
		$pages = file("data/pages.txt");

//$fp = fopen(“data/pages.txt”,“w”);
$first = 1;
foreach ($pages as $gti) {
if ($first) {
$first = 0;
}
else {
//fwrite($fp,“n”);

			}
			$inte = explode("|",$gti);
			if ($inte[0] == $page) {

//fwrite($fp,trim(implode("|",$info)));
}
else {
//fwrite($fp,trim($gti));
}
}
//fclose($fp);
}
}
$adress = “http://” . $_SERVER[‘HTTP_HOST’] . dirname($_SERVER[‘PHP_SELF’]);

include_once("data/page_header.php");

switch ($do) {
	
	case "default":
		if ($info[2] == 1 || $Siteman->mlevel >= $info[2]) {
			include_once($content);
			if ($Siteman->mlevel < 5) {

if ($page == “index”) {
if (substr_count($_SERVER[“HTTP_REFERER”],$adress) == 0) {
echo "";
}
}
}
}
break 1;
}
include_once(“data/page_footer.php”);

?>[/code] for here: http://www.phpground.net/

Just create a function that checks to make sure that the page exists and place it as the first thing that gets checked.

I couldn’t even tell you if it’s bad coding or not. Quite frankly I didn’t even look at the code. Which brings me to my first point . Why did you even post all of this code? it’s not (really) needed. Check out here -->http://www.phphelp.com/forums/viewtopic.php?t=2564 for posting guidlines.

Secondly, depending on your webserver, you can usually Re-direct errors to a particular page that is more representative to your site’s style/theme. You would have to check your documentation for your webserver.

Finally, you could certainly code it into each of your pages, but that could get tedious real quick.

Good luck and happy coding.

Small suggestion if it a possibility… try using a switch ($image). It is a little faster then the if statements and allows you to handle “none of the above” with default.

Sponsor our Newsletter | Privacy Policy | Terms of Service