php new bie Posted June 26, 2009 Share Posted June 26, 2009 hello, The problem in short .. I googled and read almost all phpfreaks help threads and try manually evreything and I failed ! I have 2 sites A and B , What i want to make user login from site A into B using curl and thats OK. After logining in the page redirect the user to next page depending on the session generated by site b like this ASP.NET_SessionId=XXXXXXXXXXXX; path=/; HttpOnly now ! it says your session has been expired -> Re-login what I do is : function login($username,$pass){ /* STEP 1. let’s create a cookie file */ $cookie_jar = tempnam('./ses/','cookie'); /* STEP 2. visit the homepage to set the cookie properly */ $ch = curl_init ("http://siteB"); curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie_jar); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); $source = curl_exec ($ch); $data = array('Username' => $username, 'Password' => $pass); $ch = curl_init ("http://SiteB_POST_PAGE"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt ($ch, CURLOPT_COOKIEFILE, "$cookie_jar"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $source = curl_exec ($ch); curl_close($ch); return $source; } echo login("name","pass"); I go to session folder and i see the generated file,every time i refresh the page a new file.tmp created with content : # Netscape HTTP Cookie File # http://curlm.haxx.se/rfc/cookie_spec.html # This file was generated by libcurl! Edit at your own risk. siteB FALSE / FALSE 0 ASP.NET_SessionId XXXXXXXXXXXXXXX . thats mean that cookies are properly stored but when login the login success and upon redirecting it says session has been expired, How can i save session to be used again and again ! Link to comment https://forums.phpfreaks.com/topic/163749-14-hrs-and-no-solution-with-curl/ Share on other sites More sharing options...
blaatschaap Posted June 26, 2009 Share Posted June 26, 2009 i got the script for you but if you delete my reply nvm then! ~Blaatschaap Link to comment https://forums.phpfreaks.com/topic/163749-14-hrs-and-no-solution-with-curl/#findComment-864058 Share on other sites More sharing options...
Tonic-_- Posted June 26, 2009 Share Posted June 26, 2009 You want to save the current session to a location on the hosting? I guess something simple like this would do.. $open = fopen("cookie.txt", "w") or die("File could not be opened."); fwrite($open, $cookie_jar); fclose($open); I don't fully get how you're getting a cookie session with curl in the first place so that probably isn't a very accurate example.. I myself use curl for a gamer card and we took a current cookie session and copied the contents to a text file and loaded it with the script. Kinda like so... // location of cookie file on server $fileLoc = "/home/blahblah/cookie.txt"; // URL Information removed for purposes (loads statistics) $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_COOKIEFILE, $fileLoc); curl_setopt($ch, CURLOPT_URL, $url); You would need to change the saving part I gave you up a lot to work properly with the script.. Be sure to make a file called cookie.txt chmodded to 0777 Link to comment https://forums.phpfreaks.com/topic/163749-14-hrs-and-no-solution-with-curl/#findComment-864070 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.