我正在尝试使用 curl 将我的用户名和密码传递给网站 www.licindia.in,但我可能遇到了 cookie 问题,我无法继续我的会话并且网站响应 302 错误,文档已被暂时移动,现在我没有得到这个代码的回应: -
<?php
$username="myusername";
$password="password";
$url="http://onlinelic.in/LICEPS/Login/webLogin.do";
//echo "praveenpuglai";
$postdata = "portlet_5_6{actionForm.userName}=".$username."&portlet_5_6{actionForm.password}=".$password;
$cookie = "JSESSIONID";
ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0");
curl_setopt($ch,CURLOPT_COOKIESESSION,true);
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_REFERER, $url);
//var_dump($ch);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
// $result = curl_exec ($ch);
//echo $result;
/*if($result != null)
{
header('Location: http://onlinelic.in/LICEPS/appmanager/Customer/CustomerHome');
} */
// curl_close($ch);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if($info['http_code'] == 301 || $info['http_code'] == 302) {
preg_match_all('|Location: (.*)\n|U', $response, $results);
$location = implode(';', $results[1]);
header("Location: $location");
exit;
} else {
$response = substr_replace($response, '', 0, strpos($response, '<', 0));
echo $response;
}
?>