php curl on submit login (codeigniter) CSFR -
where problem, don't understand.
login codeigniter framework
get message "an error encountered action have requested not allowed."
i think problem there codeigniter csfr ? how connect ?
please,
private $url = 'http://domain'; private $username = 'username'; private $password = 'password'; public function __construct() { # log # self::console('token:'.self::gettoken().' cookie:'.self::getcookie() ); # curl # self:: curl( '/admin/ajax/login', array( 'token' => self::gettoken(), 'username' => $this->username, 'password' => $this->password ) ); } private function curl( $url, $fields = null ) { $ch = curl_init(); curl_setopt($ch, curlopt_header, 0); curl_setopt($ch, curlopt_useragent,'mozilla/5.0 (x11; linux x86_64) applewebkit/537.36 (khtml, gecko) ubuntu chromium/32.0.1700.107 chrome/32.0.1700.107 safari/537.36'); curl_setopt($ch, curlopt_url, $this->url . $url ); curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_followlocation, true); curl_setopt($ch, curlopt_timeout, 600); curl_setopt($ch, curlopt_post, count($fields)); curl_setopt($ch, curlopt_postfields, !empty($fields) ? http_build_query($fields) : null ); curl_setopt($ch, curlopt_cookiejar, dirname(__file__).'\cookie.txt'); curl_setopt($ch, curlopt_cookiefile, dirname(__file__).'\cookie.txt'); $result = curl_exec($ch); if(curl_errno($ch)) { return 'curl error: ' . curl_error($ch); }else{ return print_r($result); } curl_close($ch); } private function getcookie() { $ch = curl_init(); curl_setopt($ch, curlopt_header, 1); curl_setopt($ch, curlopt_timeout, 600); curl_setopt($ch, curlopt_useragent,'mozilla/5.0 (x11; linux x86_64) applewebkit/537.36 (khtml, gecko) ubuntu chromium/32.0.1700.107 chrome/32.0.1700.107 safari/537.36'); curl_setopt($ch, curlopt_url, $this->url.'/admin/ajax/login' ); curl_setopt($ch, curlopt_returntransfer, 1); $result = curl_exec($ch); preg_match('/^set-cookie:\s*([^;]*)/mi', $result, $value); parse_str($value[1], $cookies); return $cookies['bopsystoken']; } private function gettoken() { $ch = curl_init(); curl_setopt($ch, curlopt_header,0); curl_setopt($ch, curlopt_timeout, 600); curl_setopt($ch, curlopt_useragent,'mozilla/5.0 (x11; linux x86_64) applewebkit/537.36 (khtml, gecko) ubuntu chromium/32.0.1700.107 chrome/32.0.1700.107 safari/537.36'); curl_setopt($ch, curlopt_url, $this->url.'/login' ); curl_setopt($ch, curlopt_returntransfer, 1); $result = curl_exec($ch); if(curl_errno($ch)) { return 'curl error: ' . curl_error($ch); }else{ preg_match('/type="hidden" name="token" value="(.*?)" /mi', str_replace(array("\n","\r","\t"),'',$result), $token); return $token[1]; } curl_close($ch); } private function console($e) { echo '<script>console.log("'.$e.'")</script>'; }
Comments
Post a Comment