推荐FireFox的Httpwatch和FireBug工具! $login_url = 'http://bbs.kblcw.com/logging.php?action=login'; //推荐使用FireFox的HttpWatch或者FireBug工具观察数据post或get /** * formhash a39897b7 referer loginfield username username realstd111 password tengda@@ questionid 0 answer */ $post_fields['formhash'] = 'd2dfcd3f'; $post_fields['referer'] = 'http://bbs.kblcw.com/index.php'; $post_fields['loginfield'] = 'username'; $post_fields['U53D_username'] = 'alex008'; $post_fields['password'] = '******'; $post_fields['questionid'] = 0; $post_fields['answer'] = ''; $post_fields['cookietime'] = '315360000'; $post_fields['loginmode'] = ''; $post_fields['styleid'] = ''; $post_fields['loginsubmit'] = true; //cookie文件存放在网站根目录的temp文件夹下 $cookie_file = tempnam('./','cookie'); $ch = curl_init($login_url); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)'); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_MAXREDIRS, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_AUTOREFERER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); curl_exec($ch); curl_close($ch); //带上cookie文件转向首页看看 //如果能看到用户名 则说明登录成功! $ch = curl_init('http://bbs.kblcw.com/index.php'); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); $contents = curl_exec($ch); curl_close($ch); //删除cookie文件 unlink($cookie_file); print_r($contents);