CRSF TOKEN with PHP CURL does not work -


i developing php curl automatic login website. however, in problem site need send _csrf_token server. code below. first, program called addlogindata($users), then, gettoken() , gethttpcontent().

i not know why code not work.

public function addlogindata($users) {     foreach($users $user)     {          $login_arr = array(             /*'commit' => 'login',             'nickname' => $user['username'],             'password' => $user['password'],             'save_cookie' => '1'*/             '_csrf_token' => $this->gettoken(),             'action'     => 'login',             'commit' => 'einloggen',             'invisibility' => 0,             'nickname' =>   $user['username'],             'online_status' => 0,             'password' =>   $user['password'],             'referer' => '@homepage_guest',             'remember_me' => 1         );                   array_push($this->loginarr, $login_arr);     } } public function gettoken() {        $content = $this->gethttpcontent($this->loginurl,$this->rootdomain);             $token = '';     if(!empty($content)) {                   $html = str_get_html($content);         if($html->find("input[name=_csrf_token]",0)) {             foreach($html->find("input[name=_csrf_token]") $span) {                           $token = $span->value;               }         }     }            return $token; } protected function gethttpcontent($url, $referer, $cookiepath=null, $postcontent=null, $get_info = false, $header = null) {     $ch = curl_init();     if($this->command['proxy_type'] != 3 && !empty($this->proxy_ip) && !empty($this->proxy_port) && !empty($this->proxy_type)){         curl_setopt($ch, curlopt_proxy, $this->proxy_ip);         curl_setopt($ch, curlopt_proxyport, $this->proxy_port);         curl_setopt($ch, curlopt_proxytype, $this->proxy_type);     }     curl_setopt($ch, curlopt_url, $url);     curl_setopt($ch, curlopt_referer, $referer);     curl_setopt($ch, curlopt_useragent, $this->useragent);     curl_setopt($ch, curlopt_returntransfer, 1);     curl_setopt($ch, curlopt_timeout, 60);      curl_setopt($ch, curlopt_followlocation, true);     // curl_setopt($ch, curlop  t_cainfo, dirname(__file__)."/cacert.pem");     $this->savelog("=>".$ch);        print_r($ch);     if($header !== null) {         curl_setopt($ch,curlopt_httpheader, $header);     }       if($cookiepath !== null)     {         curl_setopt($ch, curlopt_cookiefile, $cookiepath);         curl_setopt($ch, curlopt_cookiejar, $cookiepath);     }      if($postcontent !== null || $this->nullpost == 1)     {             curl_setopt($ch, curlopt_post, 1);          if($this->nullpost == 0) {             curl_setopt($ch, curlopt_postfields, (($this->_special_post == 1) ? $postcontent : http_build_query($postcontent)));             $this->_special_post = 0;             if($this->_special_post == 1){                 echo 'special search';             }             var_dump($postcontent);         }         $this->nullpost = 0;     }      $content = curl_exec($ch);     $header  = curl_getinfo($ch);      curl_close($ch);     echo '<p>url : ', $url,'</p>';     echo '<p><textarea style="width:600px; height:400px;">',$content,'</textarea></p>';      if(empty($content)) {         $this->savelog('no response url : '.$url.' / proxy : '.$this->proxy_ip.':'.$this->proxy_port); botutil::setnoresponse($this->commandid, true, $this);     } else {         botutil::setnoresponse($this->commandid, false, $this);     }      if($get_info === true) {         return array(             'header' => $header,             'content' => $content         );     } else {         return $content;     } } 

 @tufan barış yıldırım, login function below.     public function login() {     $this->useragent = botutil::getagentstring();            $this->currentuser = 0;     $username = $this->loginarr[$this->currentuser][$this->usernamefield];     $cookiepath = $this->getcookiepath($username);     $this->user_name = $username;      if(!($this->isloggedin($username)))     {         $this->savelog("this profile: ".$username." not log in.");         // count try login         for($count_login=1; $count_login<=$this->loginretry; $count_login++)         {             if($this->command["proxy_type"] == 1){                  if($this->tor_new_identity($this->proxy_ip,$this->proxy_control_port,'bot')){                     $this->savelog("new tor identity request completed.");                 }else{                     $this->savelog("new tor identity request failed.");                 }              }              $this->savelog("logging in.");              // log             $content = $this->gethttpcontent($this->loginactionurl, $this->rootdomain, $cookiepath, $this->loginarr[$this->currentuser]);             if(!empty($content)) {                 file_put_contents("login/".$username."-".date("ymdhis").".html",$content);             }               if(empty($content))             {                  $this->savelog("no response server.");                 $this->loginretry++;             }             else if(!($this->isloggedin($username)))             {                  $this->savelog("log in failed profile: ".$username);                 $this->savelog("log in failed $count_login times.");                  if($count_login>($this->loginretry-1))                 {                     $this->savelog("user ".$username." tried login ".$count_login." times. username deleted.");                     dbconnect::execute_q("update user_profiles set status='false' site_id=".$this->siteid." , username='".$this->loginarr[$this->currentuser]['data']['user'][$this->usernamefield]."'");                     $this->command['profile_banned'] = true;                     return false;                 }                 else                 {                     $sleep_time = 120; // 2 mins                     $this->_session_id = null;                     $this->savelog("sleep after log in failed ". $this->secondtotexttime($sleep_time));                     $this->sleep($sleep_time);                 }             } else {                 botutil::profilecount($this->getsiteid(), $username);                 return true;             }         }     }     else     {         return true;     } }  public function logout() {     $username = $this->loginarr[$this->currentuser][$this->usernamefield];     $cookiepath = $this->getcookiepath($username);     $this->savelog("logging out.");     $content = $this->gethttpcontent($this->logouturl. time(), $this->rootdomain, $cookiepath);     return true; } 

Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -