Forum Moderators: coopster

Message Too Old, No Replies

Includes and Error Pages

Any ideas on how to set up an error page?

         

Programmers

2:33 am on Sep 7, 2006 (gmt 0)

10+ Year Member



I have set up a basic include script and I would like to display an error page if the user types in an incorrect url but I don't know how to go about this... Here's what I currently use:

elseif ($_GET['id'] == "1")
{ $page="1.txt"; }

elseif ($_GET['id'] == "2")
{ $page="2.txt"; }

else
{ $page="1.txt"; }

include($page);

Any ideas would be appreciated,
regards,
Tom.

eelixduppy

2:37 am on Sep 7, 2006 (gmt 0)



Instead of including 1.txt in the else conditional, use error.html or something like that. Or if your script allows, you can redirect using header [us3.php.net]. ex: header("Location: error.html");

Good luck!

Programmers

10:01 am on Sep 7, 2006 (gmt 0)

10+ Year Member



Thanks for your reply.

I thought about that, and tried it but it didn't work. Because if you go to the main page which is just index.php then you get redirected to "1.txt" so if I set that to an error page, the people will get redirected every time.

eelixduppy

10:58 am on Sep 7, 2006 (gmt 0)



What I meant was something like this:

elseif ($_GET['id'] == "1")
{ $page="1.txt"; }
elseif ($_GET['id'] == "2")
{ $page="2.txt"; }
else {
header("Location: error.html");
exit();
}
include($page);

But if you are going to use header, then make sure you have nothing being sent to the browser before you call this function. Refer to the header documentation [us2.php.net] rearding this issue if you have it.

Best of luck!

Programmers

12:17 pm on Sep 9, 2006 (gmt 0)

10+ Year Member



Oh I see. I've got it sorted now. Thank you. =)