Today at 8:32am, Nathan Lane said:

I have a default PHP script in all of my directories and I want them to
redirect to my error script with some post parameters, or even variables,
and I've tried both but neither seems to do what I expect it to.

<?php
$contents = "error";
$errorNumber = 403;
$errorMessage = "Access Forbidden";
header("Location: /?page=error");
?>

After that script is run I expect the script associated with /?page=error to
see that $errorNumber and $errorMessage are set, but it doesn't see that.
Can anybody explain why?

When you call header("Location: ...") it is going to send that back to the browser, which will start a new HTTP request to grab that new location. So the variables you're setting won't be visible in that new request unless they're part of the session or something.

If you want to set up some variables then load an error page, you might consider doing it with an include() or a require() instead of a location header to redirect it. The include/require method will also be faster since it skips at least one additional round trip for the user.

Thanks,
Mac

--
Mac Newbold                     Code Greene, LLC
                                44 Exchange Place
Office: 801-582-0148            Salt Lake City, UT  84111
Cell:   801-694-6334            www.codegreene.com

_______________________________________________

UPHPU mailing list
[email protected]
http://uphpu.org/mailman/listinfo/uphpu
IRC: #uphpu on irc.freenode.net

Reply via email to