cURL Affects Cookie Retrieval in PHP?

Posted by CJ on Stack Overflow See other posts from Stack Overflow or by CJ
Published on 2010-05-02T10:33:57Z Indexed on 2010/05/02 10:37 UTC
Read the original article Hit count: 164

Filed under:
|

I'm not sure if I'm asking this properly.

I have two PHP pages located on the same server. The first PHP page sets a cookie with an expiration and the second one checks to see if that cookie was set. if it is set, it returns "on". If it isn't set, it returns "off".

If I just run the pages like
"www.example.com/set_cookie.php"
AND
"www.example.com/is_cookie_set.php"
I get an "on" from is_cookie_set.php.

Heres the problem, on the set_cookie.php file I have a function called is_set. This function executes the following cURL and returns the contents ("on" or "off"). Unfortunately, the contents are always returned as "off". however, if I check the file manually ("www.example.com/is_cookie_set.php") I can see that the cookie was set.

Heres the function :

<?php
function is_set()
{
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://example.com/is_cookie_set.php');

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$contents = curl_exec ($ch);

curl_close ($ch);

echo $contents;
}
?>

Please note, I'm not using cURL to GET or SET cookies, only to check a page that checks if the cookie was set.

I've looked into CURLOPT_COOKIEJAR, and CURLOPT_COOKIEFILE, but I believe those are for setting cookies via cURL and I don't want to do this.

© Stack Overflow or respective owner

Related posts about curl

Related posts about php