2013-10-11 6 views
0

CURL with PHP을 사용하여 원격 사이트에 로그인하도록 코드를 작성했으나 응답을받은 후 웹 사이트에서 메시지가 나타납니다 Your browsers cookie functionality is turned off. Please turn it on. 그러나 쿠키가 사용 가능하고 브라우저 로그인이 작동 중입니다. cUrl 원격 사이트에 로그인 할 수 없습니다

다음은 내가 코딩 한 내 코드입니다 :

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() 모든 숨겨진 고유 값을 가져 오는 생성자를 통해 처음 호출되며, 해당 로그인() 함수 후에 호출된다.

클래스 PARAM : FORUM_URL = https://www.chrono24.com/en/user/login.htm 이름 = [email protected] PWD : test123I

어떤 도움은 매우 감지 할 수 있어야합니다.

답변

1

로그인 페이지는 모든 요청과 함께 보내야하는 일부 쿠키를 설정합니다. 따라서 cookiejar와 -file을 FetchPage에 설정해야합니다.

+0

안녕하세요 .--) 감사합니다. – ravisoni

관련 문제