I want to create a script that can login using POST info, then browses through afew pages, on the same time. (After logging in) So I need to keep the session/cookie thing...
I've tried afew things, the logging in (POST) works fine.
But when I try to execute a second url, (the first being the login page) I lose the session/cookie and it the webpage says i'm no longer logged in:
Where am I going wrong with my code?
$url = 'http://www.example.com/authenticate.php';
$url2 = 'http://www.example.com/twourl.php';
$player = 'myuser';
$password = 'mypass';
$fields = array(
'player'=>urlencode($player),
'password'=>urlencode($password),
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
//open connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST,count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_HEADER, 0);
//execute post
curl_exec($ch);
curl_setopt($ch, CURLOPT_URL,$url2);
curl_setopt($ch, CURLOPT_HEADER, 0);
//execute two url
curl_exec($ch);
//close connection
curl_close($ch);
Why is it not keeping me logged in on the second url?