Re: session vs. header
| From: | Chris Shiflett | Date: | Thu, 07 Nov 2002 05:52:21 +0000 |
| Subject: | Re: session vs. header | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-123109@lists.php.net to get a copy of this message | ||
huge junk mail wrote:
Can someone tell me why I can't have $_SESSION['foo'] = 'content of foo'; following by header('Location: http://www.mysite.com'); Someone from www.php.net told me that it can confuse browser (http://bugs.php.net/19991). But, still I can't the idea why it can happen. Does register session means sending a 'header: location' too?You can, and you should not get any errors from PHP. The reason someone suggested that this can confuse the browser is as follows: 1. When you initiate a session, PHP tells Apache to send a Set-Cookie header (assuming you are using the default session settings). 2. When you manually set a Location header, the HTTP response status code changes from 200 OK to 302 Moved Temporarily. So, at least in the past, some Web browsers would ignore Set-Cookie headers that are sent in a response that basically says, "Hey, that thing you are looking for is over here now." Also, in some scripting languages (I believe in PHP as well, but I am not positive), the Set-Cookie headers would not even be included when you changed the status code like this, so it didn't matter what the browser thought. I have found that this problem appears to be fading fast, and I have recently used this combination without any user complaints (yet). :-) What problem are you experiencing? Chris