Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php cURL登录问题_Php_Curl_Login Script - Fatal编程技术网

Php cURL登录问题

Php cURL登录问题,php,curl,login-script,Php,Curl,Login Script,使用cURL来抓取一个安全的登录页面,我已经束手无策了。我成功地抓取了两个几乎没有问题的站点,现在我无法登录到这个站点。cURL获得了我要求它访问的所有页面,但它们都没有登录,这没有帮助。也许有人能发现我错过的错误 代码是: $url_to = 'http://fastorder.newrock.es/store2009/index.php/customer/account/loginPost/'; $url_from = 'http://fastorder.newrock.es/store20

使用cURL来抓取一个安全的登录页面,我已经束手无策了。我成功地抓取了两个几乎没有问题的站点,现在我无法登录到这个站点。cURL获得了我要求它访问的所有页面,但它们都没有登录,这没有帮助。也许有人能发现我错过的错误

代码是:

$url_to = 'http://fastorder.newrock.es/store2009/index.php/customer/account/loginPost/';
$url_from = 'http://fastorder.newrock.es/store2009/index.php/customer/account/login/';
$url_get = 'http://fastorder.newrock.es/store2009/index.php/';
$name_pass = 'login%5Busername%5D=*****&login%5Bpassword%5D=*****&send=';

function login($link,$user,$from) {
    $fp = fopen("cookie.txt", "w");
    fclose($fp);
    $log = curl_init();
    curl_setopt($log, CURLOPT_REFERER, $from);
    curl_setopt($log, CURLOPT_URL, $link);
    curl_setopt($log, CURLOPT_COOKIEJAR, "cookie.txt");
    curl_setopt($log, CURLOPT_COOKIEFILE, "cookie.txt");
    curl_setopt($log, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6");
    curl_setopt($log, CURLOPT_TIMEOUT, 40);
    curl_setopt($log, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($log, CURLOPT_HEADER, TRUE);
    curl_setopt($log, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($log, CURLOPT_POST, TRUE);      
    curl_setopt($log, CURLOPT_POSTFIELDS, $user);
    $data = curl_exec($log);
    curl_close($log);
}

login($url_to,$name_pass,$url_from);

function get($url) {
    $get = curl_init();
    curl_setopt($get, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($get, CURLOPT_COOKIEFILE, "cookie.txt");
    curl_setopt($get, CURLOPT_URL, $url);
    return curl_exec ($get);
    curl_close ($get);
}

$html = get($url_get);
echo $html;
这是在其他两个站点上运行的大致相同的脚本,它能够很好地登录。让我一开始就不舒服的是$name\u密码中的代码。事实证明,该站点已将名称和密码输入字段命名为login[username]和login[password]。为什么,我不知道,但我试着用代码和括号发送它,但没有任何帮助

Live HTTP Headers为页面提供了以下信息:

http://fastorder.newrock.es/store2009/index.php/customer/account/loginPost/

POST /store2009/index.php/customer/account/loginPost/ HTTP/1.1
Host: fastorder.newrock.es
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Referer: http://fastorder.newrock.es/store2009/index.php/customer/account/login/
Cookie: frontend=6tjul97q4mvn0046ier0k79li8
Content-Type: application/x-www-form-urlencoded
Content-Length: 81
login%5Busername%5D=*****&login%5Bpassword%5D=*****&send=
HTTP/1.1 302 Found
Date: Fri, 26 Feb 2010 12:29:19 GMT
Server: Apache/2.0.63 (CentOS)
X-Powered-By: PHP/5.2.10
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Location: http://fastorder.newrock.es/store2009/index.php/customer/account/
Content-Length: 0
Connection: close
Content-Type: text/html; charset=UTF-8
我试着把我能复制的所有东西都复制到cURL脚本中,认为有某种模糊的方法可以阻止scrip登录。但现在我完全陷入困境,不知道下一步该怎么办。我已经翻阅了很多教程,它们都给出了一些建议,对前两个网站来说非常有吸引力

Halp?

可能是这样的:

login%5Busername%5D=*****&login%5Bpassword%5D=*****&send=
我不是卷发大师,但是你的剧本看起来还不错,所以也许你不应该逃避角色


我会用curl和这种登录表单进行本地测试。也许你可以从那里调试出问题。如果我是对的,将有空字段。

建议:使用Fiddler www.fiddler2.com来区分请求流量,CURL与您的浏览器。

该商店的注册/登录有问题。激活电子邮件说,只是登录激活帐户。我已尝试登录多次,但我得到的错误是此帐户未激活。每次我尝试登录时

下面是打印返回的登录页面的快速更改

$url_to = 'http://fastorder.newrock.es/store2009/index.php/customer/account/loginPost/';
$url_from = 'http://fastorder.newrock.es/store2009/index.php/customer/account/login/';
$url_get = 'http://fastorder.newrock.es/store2009/index.php/';
$name_pass = 'login%5Busername%5D=*****&login%5Bpassword%5D=*****&send=';

function login($link,$user,$from) {
$fp = fopen("cookie.txt", "w");
fclose($fp);
$log = curl_init();
curl_setopt($log, CURLOPT_REFERER, $from);
curl_setopt($log, CURLOPT_URL, $link);
curl_setopt($log, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($log, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($log, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6");
curl_setopt($log, CURLOPT_TIMEOUT, 40);
curl_setopt($log, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($log, CURLOPT_HEADER, TRUE);
curl_setopt($log, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($log, CURLOPT_POST, TRUE);      
curl_setopt($log, CURLOPT_POSTFIELDS, $user);
$data = curl_exec($log);
curl_close($log);
return $data;
}

echo login($url_to,$name_pass,$url_from);

function get($url) {
$get = curl_init();
curl_setopt($get, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($get, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($get, CURLOPT_URL, $url);
return curl_exec ($get);
curl_close ($get);
}

$html = get($url_get);
echo $html;
编辑: cookie数据是否正在写入cookie文件cookie.txt?如果不是

检查文件权限,确保其可写

php5早期版本中的一个bug导致cookies文件选项被忽略

有关该漏洞的详细信息如下: 解决方案:在curl\u close$log之后添加unset$log


在无法测试的情况下调试这个脚本是很困难的。

是的,我也考虑过这一点。问题是,逃离他们的是网站,不是我。我从LiveHTTP头中得到了它,所以我检查了站点以查看表单。它和上面写的一模一样-登录[用户名]和登录[密码]。这意味着他们的变量应该是$\u POST['login[username]'。因此,我们逃走了。这只是糟糕的编码,但我是一个网站用户,不是所有者。是的,非常糟糕。不仅仅是代码方面。他们在一个相当主观的,私人用户的层面上宣传注册。。。然后他们只为业务用户手动打开它。所以,嗯,是的。回复:编辑代码。有趣的问题似乎出在饼干上。因为它会打印出“请启用cookies”页面。现在只想弄清楚他们到底出了什么问题/是的,没错。我忘了。您必须指定cookies文件的绝对路径。使用getcwd。添加了getcwd。到所有cookie行。还是不行Xipe,它可能是php5中的一个bug,请参阅上面对我答案的修改。是的,它根本没有被编写出来。即使我使用unset。我知道在没有登录数据的情况下调试脚本是很困难的,但是考虑到这是公司的登录,我不能给出它。我试过做一个虚拟注册,但他们不允许,所以这几乎是不可能的。