Forum Moderators: coopster

Message Too Old, No Replies

cURL and cookies

sending remote cookies

         

WhosAWhata

10:53 pm on May 5, 2005 (gmt 0)

10+ Year Member



i tried this code with the hopes that it would make the server think i had a cookie installed from their site (another of my sites, just seeing if i could do it) but it doesn't work

<?
$string = "cookie=test";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com");
curl_setopt($ch, CURLOPT_COOKIE, $string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_exec($ch);
curl_close($ch);
?>

is that not what this code does?

tmiller04

6:21 am on May 6, 2005 (gmt 0)

10+ Year Member



Hello WhosAWhata,

I might be pointing out something very silly here... but since you are using


curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

curl_exec() is returning the results as a string and not directly to the page. You might want to try:


<?
$string = 'cookie=atestcookie';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.example.com");
curl_setopt($ch, CURLOPT_COOKIE, $string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$text = curl_exec($ch);
curl_close($ch);
die($text);
?>

Otherwise, I do not see anything obviously wrong with your code for setting the cookie. Hope that is of some help!

- Travis