Re: setcookie then redirect
| From: | Chris Shiflett | Date: | Thu, 11 Jul 2002 01:46:10 +0000 |
| Subject: | Re: setcookie then redirect | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-106988@lists.php.net to get a copy of this message | ||
David Busby wrote:
List,You can't do this. Your "Set-Cookie" header is not going to be included in the HTTP response, so the browser never receives it. This is because you are using a "Location" header on the same page, which is going to take precedence. If you search the archives, you'll see more details about this behavior and some other peoples' opinions. You have two ways around this: 1. Use a meta refresh instead of a protocol-level redirect. 2. Redesign the flow of your application to better handle this behavior. Happy hacking. ChrisI'm trying to set a cookie like this:<?php function redirect() {if ($_SERVER['HTTP_HOST'] == $_SERVER['SERVER_NAME']) { $to = func_get_arg(0); header("HTTP/1.1 301\n"); header("Location:http://".$_SERVER['SERVER_NAME'].$to."\n"); header("Set-Cookie: sid=$sid;\n\n"); exit(); }}