I have tried to simulate mass login using javascript, by pasting a bunch of codes in the google chrome console.
These is what I basically do:
var data = [{u:1, p:1}, {u:2, p:2}, {u:3, p:3} ...]
function login(u,p,callback){
$.post('/login.php', {u:u, p:p}).done(function(){
logout(callback);
});
}
function logout(callback){
// delete session cookies using javascript
callback();
}
function main(){
// recursive function to iterate in the data collection
login(data[counter].u, data[counter].p, function(){
if(counter++ < data.length){
main();
}
});
}
Question
How do I do that using php curl? This is specifically about how to emulate sessions so that the "only member actions" can also be access after login.
How do I clear the session, if I don't have to use destroy sessions, in javascript you would just delete the session cookies stored in the browser. In curl php, how do I do that?
My attempt
$url = 'login.php';
$fields = array(
'u' => urlencode('1'),
'p' => urlencode('1')
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
As you can see, I tried 1 set of credentials. But beyond that, I do not know what to do.