Jump to content

Archived

This topic is now archived and is closed to further replies.

fubowl

cURL question

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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  [url=http://www.phpit.net/article/using-curl-php/]http://www.phpit.net/article/using-curl-php/[/url]

Ronald  8)

Share this post


Link to post
Share on other sites
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.

[code=php:0]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);
$var=curl_exec($ch);
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.