错误500与PHP卷曲
问题描述:
我试图做一个卷曲,登录在一个网站,问题是,我不断收到错误500 - 内部服务器错误。错误500与PHP卷曲
代码:
<?php
$path = $_SERVER["DOCUMENT_ROOT"]."/teste/ctemp";
//login form action url
$url="https://example/security_check";
$postinfo = "username=xxx&password=xxxx";
$website="https://example/account";
$base="https://example/";
$cookie_file_path = $path."/cookie.txt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
//set the cookie the site has for certain features, this is optional
curl_setopt($ch, CURLOPT_COOKIE, "cookiename=0");
curl_setopt($ch, CURLOPT_USERAGENT,
"Mozilla/5.0 (Windows; U; Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);
curl_exec($ch);
//page with the content I want to grab
curl_setopt($ch, CURLOPT_URL, $website);
//do stuff with the info with DomDocument() etc
$html = curl_exec($ch);
curl_close($ch);
$html = preg_replace("/<head>/i", "<head><base href='$base' />", $html, 1);
echo $html;
该网站是https://example/中,auth形式submited到https://example/security_check与岗位的用户名和密码,一个SUCESSFUL登录后,页面会被重定向到例如/占到
有什么问题用我的代码?
答
请,审阅你的代码,$url
变量不存在:
curl_setopt($ch, CURLOPT_URL, $url);
你应该修复它。
+0
哦,对不起,当我编辑代码时,我改变了var名称,忘记在另一行中更改。但在原始代码中,$ urlform是$ url,所以仍然存在500内部错误的问题 –
请在每一行中设置一个'var_dump('try 1').... var_dump('try n')',你会看到它的中断点。这是一种更快的做法。我希望能帮助你。 –
该代码在我试过的另一个网站上运行得非常好,问题仅在于我尝试卷曲的这个问题,我做了一些调查,看起来是因为存储在登录页面中的Cookie,我打电话给auth形式直接通过邮件,任何提示为此? –
如果您应该向我发送完整的代码或发送给我链接,我需要对其进行测试。 –