this is what I’m trying to do:
- pass a form with a curl statement using POST variable => good
- after i’m logged in the website go to whichever page I want => not good
here is my script for now:
$postData = array(
'login' => 'john',
'pwd' => 'doe'
);
$array_url = array('3109');
foreach ($array_url as $k => $i) {
echo $i."<br>";
$c = curl_init();
$url = "http://mywebsite/index.php?ok=1";
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($c, CURLOPT_POSTFIELDS, $postData);
$output = curl_exec($c);
if ($output === false) {
trigger_error('Erreur curl : ' . curl_error($c), E_USER_WARNING);
}
else {
var_dump($output);
echo $output;
}
curl_close($c);
}
How can I achieve this ?
edit: If I try to fetch the page I would like to consult I get redirect to the login form cause I can’t set the couple login/pass from this page, I need to fetch the checkingpassword one…
Thx
You need to determine how the remote page is authenticating sessions. Most sites do this using a cookie. Once you’ve logged in, any consecutive page requests pass the cookie, the remote site checks the cookie, if it is valid and not expired, it lets you through, otherwise, it kicks you back to the login page (or gives you an error, or whatever).
So if it’s a cookie, you need to store the cookie that’s returned, and use that in any subsequent curl requests.