Re: redirect without using header
| From: | Chris Shiflett | Date: | Thu, 14 Nov 2002 05:14:09 +0000 |
| Subject: | Re: redirect without using header | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-124383@lists.php.net to get a copy of this message | ||
pig pig wrote:
The problem I am expriencing now is intermittent. Sometime the CGI error will appear and sometime it works fine. Could it be the latency in the network that is causing the problem? Just before the call to header() there is a db query.Someone else might have suggested this, but a good way to debug any header() related problem is to remove the call to header() and replace it with some sort of debugging output. For example, if you had the following script ... <? if ($blah;) {
$foo="bar";} header("Location: http://www.php.net/"); ?> ... you will get a parse error because of the statement on line 2. This parse error gets output just like an echo statement would, so it creates another error when you try to then manipulate the HTTP headers. This error is usually the one you will see on the screen. If you don't catch the syntax error, you might not see how it is possible that any output occurs before the header() call. If you replace this code with this ... <? if ($blah;) {
$foo="bar";} echo "<h3>[Location: http://www.php.net/]</h3>"; ?> ... you will see the parse error as well as the value of the header you were going to send (which might not be static as illustrated here) on the screen. This can reveal some really frustrating bugs sometimes. Of course, I am assuming your error was something like, "headers already sent on line ...", so if that isn't the error, this might all be useless advice. :-) Chris