Login in via curl then open that page logged in
- by user207022
I'm trying the following code to send post data to the login form, then reload that page in the browser as a logged in user. somehow it's not saving the cookie, and reusing it for the header() function, can the same thing as header be done by calling curl again after sending the login details?
..
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER , false );
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST , false );
curl_setopt($ch, CURLOPT_USERAGENT, $defined_vars['HTTP_USER_AGENT']);
//curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
// Apply the XML to our curl call
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$data = curl_exec($ch);
setcookie($cookie);
header('location: ' . $url);
die();