Jump to content


cURL question

  • Please log in to reply
2 replies to this topic

#1 fubowl

  • Members
  • PipPipPip
  • Advanced Member
  • 37 posts

Posted 16 September 2006 - 12:09 PM

I am trying to submit a form to get specific results. The problem is that the server I'm trying to get it from using a session cookie to log the result and then destroys it. I've been trying to get a result using cURL but am unsure of how to go about it. I have the search form but cannot follow it using cURL. However, I am more interested in getting the results.

Can you set cURL to follow a submitted form?

If not, how can you go about showing results in such a circumstance.

I know you can go about pre-filling CURLOPT_POSTFIELDS but I have not had success in doing so, or is there an easier way?

I would really appreciate a working example, everything I've tried to this point has failed.

#2 ronverdonk

  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 16 September 2006 - 12:27 PM

I am just a curl beginner, but I think you have to use the CURLOPT_RETURNTRANSFER  option. See form more info on this the PHPit article at  http://www.phpit.net...using-curl-php/

Ronald  8)
RTFM is an almost extinct art form, it should be subsidized.

#3 michaellunsford

  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 16 September 2006 - 04:53 PM

Here's what I'm using to do the same thing... It uses postfields, followlocation, and a cookiejar. You just string the post fields together like you would using the GET method -- but curl will POST them instead.

if(file_exists("my_cookies.txt")) unlink("my_cookies.txt");
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/someform.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "userid=".$user[0]."&password=".$user[1]);
curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt"); 
curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt"); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_VERBOSE, 1); 
curl_setopt($ch, CURLOPT_FAILONERROR, 1); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412.6 (KHTML, like Gecko) Safari/412.2");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users