set_cookie problem via file_get_contents

From: will (spam_at_sourceymonkey.com)
Date: 11/13/03


Date: 12 Nov 2003 15:57:09 -0800

Hiya,
Iam writing a bit of code that will check to see how I should deal
with the user for the rest of the session - cookies, session or use
their ip. The problem Im having is that set_cookie doesnt work (or
$_SESSION='asda';) when called by the file_get_contents but does on
its own.

testcookie.php:

$checkcc = file_get_contents ("http://somesite/cookies.php?c=cc");
echo "checkcc: $checkcc <br>";

cookies.php:

if ($_GET['c']=='cc'){
/* cookies */
    if ($_GET['mode']!=="test") {
           $res = setcookie("COOKIE", "VALUE");
             header("Location:
".$_SERVER['SCRIPT_NAME']."?c=cc&mode=test&res=$res");
            exit;
    } else if ($_COOKIE['COOKIE']=="VALUE") {
            echo "1";
            setcookie ("COOKIE", "", time() - 3600);
    } else {
            echo "No Cookies Set $res";
    }
}

Output = "No Cookies Set 0"
(which seems to suggest the redirect is working under
file_get_contents which is ace)
pulling the link:
http://somesite/cookies.php?c=cc in a browser does work fine.

any ideas much appreciated. Im guessing one fix may be to use curl to
deal with this
Incase you ask - Im doing it like this on a seperate script because I
cant refresh the script that calls it ( I do header outputting later
on for one reason)

cheers

will



Relevant Pages