Jump to content

cURL question


fubowl

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.