irishdaddy Posted December 9, 2006 Share Posted December 9, 2006 I'm brand new to using cURL and I am trying to log into a vBulletin based forum (just like this one).At this point I can get it to say "Thanks for logging in [username], wait while we redirect you", but once I get to the forums, the script is obviously not logged in anymore. So it is as if the server OK's the authentication, but once I get to the forums it doesn't know I'm logged in. This leads me to believe it is a *cookies* problem. Here is what I have as my code:[CODE]$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, $data);$result = curl_exec($ch);$source = "http://forumname.com/forums";$contents = file_get_contents($source);echo $contents;[/CODE] I chmodded my cookie.txt to (777), but they are empty after the script runs.Any ideas? This has been *KILLING* me ALL day yesterday and today. I will name my first born after whoever can fix this for me. Link to comment https://forums.phpfreaks.com/topic/30048-curl-to-login-to-forum/ Share on other sites More sharing options...
artacus Posted December 9, 2006 Share Posted December 9, 2006 This can get tricky. See what cookies the site sets by logging in normally. Try using that to seed your cookie.txt file. Link to comment https://forums.phpfreaks.com/topic/30048-curl-to-login-to-forum/#findComment-138155 Share on other sites More sharing options...
irishdaddy Posted December 9, 2006 Author Share Posted December 9, 2006 [code]Set-Cookie: s_vi_x7Fbfnhddx60bel=[CS]v4|457A11C0000056CD-A160B3100003DE9|457B0F10[CE]; Expires=Thu, 8 Dec 2011 19:36:40 GMT; Domain=.2o7.net; Path=/[/code]Is what came out when I used "liveHeaders" with a normal login to the site. So I just dump this line into my cookie.txt file? I tried that.Do I need to modify my code any? Link to comment https://forums.phpfreaks.com/topic/30048-curl-to-login-to-forum/#findComment-138169 Share on other sites More sharing options...
mainewoods Posted December 10, 2006 Share Posted December 10, 2006 curl_setopt has this other parameter you can try:CURLOPT_COOKIESESSION TRUE to mark this as a new cookie "session". It will force libcurl to ignore all cookies it is about to load that are "session cookies" from the previous session. By default, libcurl always stores and loads all cookies, independent if they are session cookies are not. Session cookies are cookies without expiry date and they are meant to be alive and existing for this "session" only. Available since PHP 5.1.0. Link to comment https://forums.phpfreaks.com/topic/30048-curl-to-login-to-forum/#findComment-138290 Share on other sites More sharing options...
mainewoods Posted December 10, 2006 Share Posted December 10, 2006 mr at coder dot tv14-Apr-2006 07:22 Sometimes you can't use CURLOPT_COOKIEJAR and CURLOPT_COOKIEFILE becoz of the server php-settings(They say u may grab any files from server using these options). Here is the solution1)Don't use CURLOPT_FOLLOWLOCATION2)Use curl_setopt($ch, CURLOPT_HEADER, 1)3)Grab from the header cookies like this:preg_match_all('|Set-Cookie: (.*);|U', $content, $results); $cookies = implode(';', $results[1]);4)Set them using curl_setopt($ch, CURLOPT_COOKIE, $cookies); Link to comment https://forums.phpfreaks.com/topic/30048-curl-to-login-to-forum/#findComment-138293 Share on other sites More sharing options...
mainewoods Posted December 10, 2006 Share Posted December 10, 2006 mcknight at chek dot com22-Aug-2005 08:10 when specifing the file for either CURLOPT_COOKIEFILE or CURLOPT_COOKIEJAR you may need to use the full file path instead of just the relative path. Link to comment https://forums.phpfreaks.com/topic/30048-curl-to-login-to-forum/#findComment-138295 Share on other sites More sharing options...
mainewoods Posted December 10, 2006 Share Posted December 10, 2006 PHP/CURL Examples Collectionhttp://curl.haxx.se/libcurl/php/examples/ Link to comment https://forums.phpfreaks.com/topic/30048-curl-to-login-to-forum/#findComment-138296 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.