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
https://forums.phpfreaks.com/topic/223557-php-curl-submit-form-after-login/
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.

Archived

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

×
×
  • 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.