curl 模拟登陆成功以后,访问页面返回500错误。
<?php
header("Content-type: text/html; charset=utf-8");
require_once('yanzheng.php');
require_once('include/function.php');
// 登录系统
$url = "http://";
$post = array(
'Id' => '888',
'username' => 8888',
'password' => '8888', //密码
'captcha' => $_POST["yzm"],); //验证码
$login = curl_open($url,array('post'=>$post));
if (!strpos($login,"管理系统")) exit("登录失败");
//访问,不需要post参数,不登录访问这个网址,会返回302,跳转到登录页面。
$url = "http://";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) .'/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) .'/cookie.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>
返回
HTTP/1.1 500 Internal Server Error
Date: Sun, 15 May 2011 05:15:45 GMT
Server: Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/0.9.8o mod_jk/1.2.30
Cache-Control: max-age=0
Expires: Sun, 15 May 2011 05:15:45 GMT
Vary: Accept-Encoding
Content-Length: 2696
Connection: close
Content-Type: text/html;charset=UTF-8
//其中的函数
function curl_open($url, $conf = array())
{
if(!function_exists('curl_init') or !is_array($conf)) return FALSE;
$post = '';
$purl = parse_url($url);
$arr = array(
'post' => FALSE,
'return' => TRUE,
'cookie' => dirname(dirname(__FILE__)) .'/cookie.txt',);
$arr = array_merge($arr, $conf);
$ch = curl_init();
if($purl['scheme'] == 'https')
{
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, $arr['return']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $arr['cookie']);
curl_setopt($ch, CURLOPT_COOKIEJAR, $arr['cookie']);
if($arr['post'] != FALSE)
{
curl_setopt($ch, CURL_POST, TRUE);
if(is_array($arr['post']))
{
$post = http_build_query($arr['post']);
} else {
$post = $arr['post'];
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
返回页面有个提示:java.lang.NullPointerException
求大家帮帮忙啊,很急。