I try to login usin Curl, everything must be ok but finally it says like security token xyz is invalid and then i have to manually click the login button to continue. bellow is the final link it stops:
my guess is i don't know what real path to save the cookie!
any idea please how to solve this login using curl ? this is my code:
Code:
http://www.example.ir:2082/cpsess0807585904/frontend/paper_lantern/index.html?login=1&post_login=2531456137975
any idea please how to solve this login using curl ? this is my code:
Code:
function createSession() { // Example details
$ip = "127.0.0.1";
$cp_user = "myUser";
$cp_pwd = "myPass";
$url = "http://www.example.ir:2082/login";
$cookies = "cookies.txt";
// Create new curl handle
$ch=curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies );
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies ); // Save cookies to
curl_setopt($ch, CURLOPT_POSTFIELDS, "user=$cp_user&pass=$cp_pwd");
curl_setopt($ch, CURLOPT_TIMEOUT, 100020);
$f = curl_exec($ch);
$h = curl_getinfo($ch);
curl_close($ch);
$luckyUrl = $h['url'];
// If we had no issues then try to fetch the cpsess
if ($f == true and strpos($h['url'],"cpsess"))
{
// Get the cpsess part of the url
$pattern="/.*?(\/cpsess.*?)\/.*?/is";
$preg_res=preg_match($pattern,$h['url'],$cpsess);
}
header("Location: ".$luckyUrl);
// If we have a session then return it otherwise return empty string
return (isset($cpsess[1])) ? $cpsess[1] : "";
}
echo createSession();
Last edited by a moderator: