Php cUrl无法登录到远程站点
我已经使用Php cUrl无法登录到远程站点,php,curl,Php,Curl,我已经使用CURL with PHP编写了登录远程站点的代码,但是在得到响应后,我从网站上收到一条消息,提示您的浏览器cookie功能已关闭。请将其打开。但是cookies已启用,并且浏览器登录到站点正在工作 以下是我已编码的代码: function __construct($forum_url,$username,$password){ if(!function_exists('curl_init')){ trigger_error('api_chron
CURL with PHP
编写了登录远程站点的代码,但是在得到响应后,我从网站上收到一条消息,提示您的浏览器cookie功能已关闭。请将其打开。
但是cookies已启用,并且浏览器登录到站点正在工作
以下是我已编码的代码:
function __construct($forum_url,$username,$password){
if(!function_exists('curl_init')){
trigger_error('api_chrono::error, Sorry but it appears that CURL is not loaded, Please install it to continue.');
return false;
}
if(empty($forum_url)){
trigger_error('api_chrono::error, The forum location is required to continue, Please edit your script.');
return false;
}
$this->forum_url = $forum_url;
$this->cookie_path = plugin_dir_path(__FILE__).'cookies/'.md5($forum_url).'.txt';
$this->deleteCookie();
$this->username = $username;
$this->password = $password;
$this->FetchPage();
}
private function FetchPage(){
$this->curl = curl_init();
curl_setopt($this->curl, CURLOPT_URL,$this->forum_url);
curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($this->curl, 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($this->curl, CURLOPT_TIMEOUT, 60);
curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER,1);
curl_setopt($this->curl, CURLOPT_REFERER,$this->forum_url);
$page = curl_exec($this->curl);
include('ganon.php');
$dom = str_get_dom($page);
$this->continueTo = $dom('input[name="continueTo"]',0)->getAttribute('value');
$this->changeLogInPermanentlyPref = $dom('input[name="changeLogInPermanentlyPref"]',0)->getAttribute('value');
$this->_sourcePage = $dom('input[name="_sourcePage"]',0)->getAttribute('value');
$this->__fp = $dom('input[name="__fp"]',0)->getAttribute('value');
}
public function login(){
$postdata = "email=".$this->username."&password=".$this->password."&logInPermanently=1&continueTo=".$this->continueTo."&_sourcePage=".$this->_sourcePage."&
__fp=".$this->__fp."&login=Login";
//$this->curl = curl_init();
curl_setopt($this->curl, CURLOPT_URL,$this->forum_url);
curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($this->curl, 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($this->curl, CURLOPT_TIMEOUT, 60);
curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER,1);
curl_setopt($this->curl, CURLOPT_COOKIEJAR,$this->cookie_path);
curl_setopt($this->curl, CURLOPT_COOKIEFILE,$this->cookie_path);
curl_setopt($this->curl, CURLOPT_REFERER,$this->forum_url);
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($this->curl, CURLOPT_POST,1);
echo $page = curl_exec($this->curl);
//curl_setopt($this->curl,CURLOPT_URL,'www.chrono24.com/en/dealer-area/index.htm');
//echo curl_exec($this->curl);
//Error handling
if(curl_errno($this->curl)){
$this->error = array(
curl_errno($this->curl),
curl_error($this->curl),
);
curl_close($this->curl);
return $this->error;
}
return true;
}
FetchPage()首先通过构造函数调用,以获取所有隐藏的和唯一的值,然后调用login()函数
类参数:
论坛地址=
用户名=拉维。soni@ideavate.com
pwd:test123I
任何帮助都应该非常有用。登录页面将设置一些cookies,您必须在每次请求时发送这些cookies。因此,您还必须在
FetchPage
中设置cookiejar和-file