beyzad Posted January 18, 2009 Share Posted January 18, 2009 Hi. I need to read some contents from a CURL session. Then post data again with the same session. is there anyway to do that? I mean somethings like Fake Yahoo! ID makers that shows the CAPTCHA to user, then submit form. Thanks Quote Link to comment Share on other sites More sharing options...
shlumph Posted January 18, 2009 Share Posted January 18, 2009 I believe if you don't close the session; you can use it again... Quote Link to comment Share on other sites More sharing options...
beyzad Posted January 18, 2009 Author Share Posted January 18, 2009 SHould i use curl_init() again or not? If i not, I'll receive an error. else, that's not work. Quote Link to comment Share on other sites More sharing options...
shlumph Posted January 18, 2009 Share Posted January 18, 2009 This won't work? I believe I've done this before... <?php //Create the curl session $curl_handle=curl_init(); //Go to site 1 curl_setopt($curl_handle,CURLOPT_URL,'http://example.com'); curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2); $site1 = curl_exec($curl_handle); //Now go to site 2 curl_setopt($curl_handle,CURLOPT_URL,'http://www.asdf.com'); curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2); $site2 = curl_exec($curl_handle); //Now close curl_close($curl_handle); Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted January 18, 2009 Share Posted January 18, 2009 I assume you're logging into a website first and then trying to retrieve some information? You'll need to specify a COOKIEJAR so that any cookies created by the first request (i.e. the session id) can be stored and used in the second request. And no, you don't make two calls to curl_init(). Quote Link to comment Share on other sites More sharing options...
beyzad Posted January 18, 2009 Author Share Posted January 18, 2009 That's working, but with different sessions. i need to keep the first url session. Quote Link to comment Share on other sites More sharing options...
beyzad Posted January 19, 2009 Author Share Posted January 19, 2009 I fount this on php.net: <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_COOKIEFILE, "cookiefile"); curl_setopt($ch, CURLOPT_COOKIEJAR, "cookiefile"); curl_setopt($ch, CURLOPT_COOKIE, session_name() . '=' . session_id()); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_URL, 'http://site.com/page1.php'); $result1 = curl_exec($ch); curl_setopt($ch, CURLOPT_URL, 'http://site.com/page2.php'); $result2 = curl_exec($ch); curl_close($ch); ?> But i still cant understand how to grab somethings from the first URL, then post them to the second url? Please help me. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted January 19, 2009 Share Posted January 19, 2009 To get something from the first page to use in the second request, you'll need to extract the information from the first request. You have the source of the page stored in $result1, so you could use regular expressions to get the data you need (e.g. preg_match). Without actually knowing what sort of information you're trying to retrieve, it's hard to give you any more specific help than that. Quote Link to comment Share on other sites More sharing options...
beyzad Posted January 19, 2009 Author Share Posted January 19, 2009 Exuse me.. I need to grab CAPTCHA image from the first URL and show that to the user, Then POST data to the second URL with same session. Thanks for your help. Quote Link to comment Share on other sites More sharing options...
beyzad Posted January 20, 2009 Author Share Posted January 20, 2009 Please help.... Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted January 20, 2009 Share Posted January 20, 2009 I'm not overly convinced on why you'd want to do this...but anyway. You'll need to make the request to the first page, storing the cookie that is set and extracting the image name. Of course, if the image name is always the same, you don't actually need to bother, though you do still need to make the request to the first page to have the cookie set. Show the user the image. Then make the second request, providing the cookie data you saved from the first one. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.