Jump to content

PHP CURL SUBMIT FORM AFTER LOGIN


radio86

Recommended Posts

Hi Guys

 

I can login into the site, a session is created and stored in cookies.txt but i dont know how to begin the next step where the script needs to submit another form in the members area on the same website. basically the plan is, i create my own form and send data to curl script which will login into external website form, create session, then send data created from my own form to to external website members form page. This way i will be able to store the data on my database and sent to them. But now i am lost. Please help me, thanks in advance

 

function getData($data)
{
$query = "";
foreach ($data as $value => $name)
{
	$query.=$value."=".$name."&";
}
return $query;
}

$var = substr(getData($_POST),0,-1); 
$headers = array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0. Gecko/20061025 Firefox/1.5.0.8");

// INIT CURL
$ch = curl_init();

// SET URL FOR THE POST FORM LOGIN
curl_setopt($ch, CURLOPT_URL, 'http://site.com/page.php');

// ENABLE HTTP POST
curl_setopt ($ch, CURLOPT_POST, 1);

// SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'user=radio86&pass=phpfreaks');
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_MAXREDIRS, 4);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . "/cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . "/cookies.txt");

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

$content = curl_exec ($ch);

 

Link to comment
Share on other sites

where the script needs to submit another form in the members area on the same website

 

The cURL "client" (as such) is remembered by the server because of the COOKIEJAR/COOKIEFILE and the fact that a session is stored on the server.

 

Submitting another form in a login protected area shouldn't be a problem.  Just be sure to call your authentication function before your do-something-when-authed function.

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.