David Busby wrote: > List, > I'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(); > } > }
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. Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php