kireol Posted April 29, 2008 Share Posted April 29, 2008 So I have a script that I wrote 2 years ago that uses cookies just fine with cURL. I started writing a new script, so I copied and started editing the new script. Now, the old file works with cookies and the new one doesnt. I stripped the new file down to basics and found a simple site that uses cookies. I verified with firefox that the site does produce cookies. but they are not saved in the cookie file this generates. Please help me figure out why. <?php function getpage($url) { $agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)"; $ch = curl_init(); $cookies = "cookies/cookiejar.txt"; // Please set your Cookie File path if ($cookies != '') { if (substr(PHP_OS, 0, 3) == 'WIN') {$cookies = str_replace('\\','/', getcwd().'/'.$cookies);} $fp = fopen("$cookies","w") or die("<BR><B>Unable to open cookie file $cookies for write!<BR>"); fclose($fp); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies); } else { echo "COOKIES NEED TO BE SET UP\n";exit; } curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $result = curl_exec ($ch); return($result); } $result = getpage("http://www.echoecho.com/samplecookie2.htm"); ?> Link to comment https://forums.phpfreaks.com/topic/103359-curl-and-cookies/ Share on other sites More sharing options...
kireol Posted April 29, 2008 Author Share Posted April 29, 2008 I did a bit more testing and still stuck. here's some more results. If i change to stdout on the cookie file curl_setopt($ch, CURLOPT_COOKIEJAR, '-'); it DOES print out a cookie to the screen. This cookie, however, is not saving to the cookie file. If I copy and paste that cookie info, into the cookie file, then re-run the script, php clears out my cookie file back to null. arggggggg! Link to comment https://forums.phpfreaks.com/topic/103359-curl-and-cookies/#findComment-529344 Share on other sites More sharing options...
kireol Posted April 29, 2008 Author Share Posted April 29, 2008 nm, working now. too tired to compare and see why. bed time Link to comment https://forums.phpfreaks.com/topic/103359-curl-and-cookies/#findComment-529351 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.