Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 7th, 2006, 08:49 AM
Authorized User
 
Join Date: May 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to guillermo
Default header redirect not working

I'm tyring to use the code below to re-direct to an error page with the header() function, but for some reason it's not working. I know I must be doing something stupid -- I've been working on it for a few hours and can't figure it out. Any help would be appreciated. Oh, and headers aren't being sent before I reach this point... I had a check in there for that just to make sure (which I'll probably throw back in there) but I took it out to simplify the code while debugging.

try {
    SUR_Controller::route();
} catch (Exception $e) {
    $codes = array( 401 => '401 Unauthorized',
            403 => '403 Forbidden',
            404 => '404 Not Found',
            500 => '500 Internal Server Error');
    $error = ($e->getCode() == 0) ? 500 : $e->getCode();
    if (in_array($error, $codes)) {
        header($_SERVER['SERVER_PROTOCOL'] . $codes[$error]);
        exit();
    }
}
 
Old June 9th, 2006, 09:10 AM
Authorized User
 
Join Date: May 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to guillermo
Default

got it... when running php5 as cgi, you have to do format the header call like this, for example:

header("Status: 404 Not Found");

That sends the header, but I still have to force the redirect on my own it seems... if anyone has any further insight on this, please share it.

 
Old June 23rd, 2006, 05:33 AM
Registered User
 
Join Date: Jun 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Configure your php.ini file and set the following directive:
cgi.force_redirect = 1

That should solve your problem.

Have fun,
Dale

Ctrl-Alt-Del





Similar Threads
Thread Thread Starter Forum Replies Last Post
My redirect still don't working right ludigova Beginning PHP 3 October 5th, 2007 06:15 PM
redirect:write printing xml header in output csv jon.london XSLT 4 October 1st, 2007 05:47 AM
Q. How do I redirect users? (Location Header) richard.york PHP FAQs 0 April 3rd, 2004 07:40 PM
Header functions is same to asp respose.redirect() knight Beginning PHP 3 March 12th, 2004 04:06 PM
header redirect dazednconfused Beginning PHP 5 September 9th, 2003 01:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.