php curl错误500

时间:2016-04-15 01:28:59

标签: php curl

我正在努力做一个登录一个网站的卷曲,问题是我一直收到错误500 - 内部服务器错误。

代码:

<?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/,使用帖子用户名和密码将授权表单提交到https://example/security_check,登录成功后,页面将重定向到示例/帐户
我的代码有问题吗?

1 个答案:

答案 0 :(得分:0)

请审核您的代码,$url变量不存在:

curl_setopt($ch, CURLOPT_URL, $url);

你应该修理它。