首先我要做的事: 我想访问一个登录页面,以便我可以登录。该网站是Https并且需要设置Cookie我正在使用jquery运行PHP + Curl为我获取该页面并存储Cookie。嗯,我已经能够获得饼干,但我不断收到一个弹出Cookies不设置。所以,我看着它多了很多,发现JavaScript并进行初步核对,看看启用了Cookie:https,jquery,PHP,Curl和document.cookie
function initLogin(){
// check if cookie is enabled so applications can run
if (document.cookie == "") {
alert("Cookies are disabled. Cannot access mid-tier with this setting.\nPlease configure your browser to accept cookies.");
return;
}
....Other Code...
}
我经历只是在这个论坛上每一个岗位看去,尝试了不同的代码的废话负载但没有运气。所以问题是如何克服这一点?我的内容是:jquery在代理/服务器上调用php脚本,并调用curl让我访问网页。然后Curl会保存这些cookies供以后使用,但是您如何使用它们。我认为只要将它们设置在cookie文件中就足够了,但我想我错了。所以我厌倦了将它们设置为CURLOPT_COOKIE,但我不知道这是否正确。
下面是代码的拷贝,我运行:
function getpage(){
$fullurl = "https://url/arsys/shared/login.jsp?/arsys/home";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $fullurl);
$output = curl_exec ($ch);
preg_match_all('|Set-Cookie: (.*);|U', $output, $results);
$newcookies = implode(';', $results[1]);
echo "<br>COOKIES:" . $newcookies;
curl_setopt ($ch, CURLOPT_COOKIE, $newcookies);
echo curl_error($ch) . " " . $output;
curl_close($ch);
}
输出从上面的代码: 曲奇饼:JSESSIONID = B4830242479D3DFD3235D17EE6A4DEB8; Q = “” HTTP/1.1 200 OK缓存控制:NO-缓存Content-Type:text/html; charset = UTF-8服务器:Microsoft-IIS/7.5 Set-Cookie:JSESSIONID = B4830242479D3DFD3235D17EE6A4DEB8;路径=/ARSYS; Secure Set-Cookie:q =“”;到期日=星期四,1970年1月1日00:00:10 GMT;路径= /时间:星期五,2012年4月20日17时57分17秒GMT的Content-Length:35657
我也试过:
function getpage(){
$ckfile = "cookies/cookie.txt";
$fullurl = "https://url/arsys/shared/login.jsp?/arsys/home";
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $fullurl);
$output = curl_exec ($ch);
curl_close($ch);
}
的饼干得到保存在正确的文件,但仍然得到了同样的信息。
我试着在谷歌的代码,它工作正常的是阻止我的JavaScript ..