Re: setcookie then redirect + Answer

From: Date: Wed, 10 Jul 2002 23:53:01 +0000
Subject: Re: setcookie then redirect + Answer
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-106980@lists.php.net to get a copy of this message
Read your data from $_COOKIE not $_COOKIES. 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();
    }
} function login() {
    [... validation code here ...]
    // set my cookie
    setcookie("sid", $sid);
    return true;
} if (login($token) == true) {
    redirect("/somepage.php");
} ?> but this thing isn't working...seems like it's not writing the SID value in the cookie. In other code (on /somepage.php for example) when I read the cookie value ($_COOKIES['sid']) it can't find it. Ideas? So how do I set cookies then redirect? I'm using Apache 1.3.x, PHP 4.1.2, RH7.3 TIA /B


« previous php.general (#106980) next »