我在 PHP 中使用 cURL 登录到我的远程服务器。我已成功登录远程 URL,但似乎无法显示该页面的内容。到目前为止,这是我的代码:
<?php
$username = 'Blah';
$password = 'BlahBlah';
$ch = curl_init();
$postdata="email=$username&password=$password";
curl_setopt ($ch, CURLOPT_URL,"http://www.example.com/login.php");
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_HEADER, true);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt ($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt ($ch, CURLOPT_REFERER, "http://www.example.com/login.php");
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec($ch);
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/User/Home.php") ;
$result2 = curl_exec($ch) ;
echo $result2 ;
curl_close($ch);
?>
当我尝试 echo$result2
时,什么都没有。屏幕上没有打印任何内容。我需要做什么才能将内容打印到屏幕上?
这是 HTTP 标头输出:
HTTP/1.1 302 Moved Temporarily Date: Sun, 26 May 2013 23:46:40 GMT Server: Apache/2.2.23 (Unix) mod_ssl/2.2.23 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4 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 Set-Cookie: current_page=Home.php; expires=Wed, 24-May-2023 23:46:40 GMT Location: http://www.example.com/?redirected=3 Vary: Accept-Encoding,User-Agent Content-Length: 0 Content-Type: text/html HTTP/1.1 200 OK Date: Sun, 26 May 2013 23:46:40 GMT Server: Apache/2.2.23 (Unix) mod_ssl/2.2.23 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4 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 Vary: Accept-Encoding,User-Agent Transfer-Encoding: chunked Content-Type: text/html