freeloader Posted May 28, 2008 Share Posted May 28, 2008 Hi guys, I wrote a small app that would login on a website, get some statistics and post them back to me. The login procedure is pretty long (takes 3 pages >> login >> redirect >> accept terms >>), I wanted to make it go more smooth and saw they used cookies for verification. If you have the cookie with nick and pass, it assumes you have it from previous session and creates a new session id. I just need to set a cookiefile with following cookies: myNick myPass PHPSESSID I'm guessing I go about that like this: $cookie_file_path = "test.txt"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); $res=curl_exec($ch); curl_close($ch); But how do I define the cookies in the $cookie_file_path file? I looked at the headers and based on that wrote this in test.txt: PHPSESSID=hkdtdc6c8bcm5t8a9drk866na8; myNick=******; myPass=****** Either the above cURL is wrong and it just doesn't accept my cookie (seems likely since my test.txt file hasn't been overwritten), or the way I define the cookie is wrong. Any input is welcome Link to comment https://forums.phpfreaks.com/topic/107628-cookies-with-php-curl/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.