Hello.

I want to write an authorization script on ask.fm, but the problem arose already in the first step. In general, there were already many identical problems, in connection with which I was quitting work on this script, but this time I decided to write here. Below is my script. In response, he says that something went wrong, but I think that this is some kind of protection. I am new to authorization on sites through php cUrl, so please be loyal to this issue :)

<?php function get($url = null, $data = array(), $cookie = null) { $ch = curl_init(); $headers = array( "accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "accept-language:ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4", "user-agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.3.2924.87 Safari/537.36" ); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); if(isset($data)) { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); } if(isset($cookie)) { curl_setopt($ch, CURLOPT_COOKIE, $cookie); } $response = curl_exec($ch); preg_match_all("/Set-Cookie: (.*?);/", $response, $cookie); $content = substr($response, curl_getinfo($ch, CURLINFO_HEADER_SIZE)); $header = substr($response, 0, curl_getinfo($ch, CURLINFO_HEADER_SIZE)); return array( "content" => $content, "header" => $header, "cookie" => implode(";", $cookie[1]) ); } $homepage = get("https://ask.fm/"); print_r($homepage); ?> 
  • You can add an array of data. What do you convey in it? - Kostiantyn Okhotnyk
  • Nothing yet, because I want to parse the authorization token from the page. - ikerya
  • Do you have a login and password? - Kostiantyn Okhotnyk

2 answers 2

Try this ( source ):

 <?php $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, 'http://ask.fm'); curl_setopt($curl, CURLOPT_USERAGENT, "Opera/10.00 (Windows NT 5.1; U; ru) Presto/2.2.0"); curl_setopt($curl, CURLOPT_TIMEOUT, 10); curl_setopt($curl, CURLOPT_COOKIEJAR, 'cook.txt'); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $html = curl_exec($curl); curl_close($curl); preg_match('/var AUTH_TOKEN = "([\w\W]+)";/Ui',$html,$matches); $token = $matches[1]; $post = array( 'authenticity_token' => $token, 'login' => 'myUsername', 'password' => 'myPassword', ); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, 'http://ask.fm/session'); curl_setopt($curl, CURLOPT_USERAGENT, "Opera/10.00 (Windows NT 5.1; U; ru) Presto/2.2.0"); curl_setopt($curl, CURLOPT_TIMEOUT, 10); curl_setopt($curl, CURLOPT_COOKIEJAR, 'cook.txt'); curl_setopt($curl, CURLOPT_COOKIEFILE, 'cook.txt'); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $post); curl_exec($curl); curl_close($curl); ?> 
  • Thank. Pushed to the decision. - ikerya

You can get the page like this:

  class Ask { private $userAgent ; private $login = null; private $password = null; private $url = null; private $responce = null; private function utfToWin($text) { $text = iconv('UTF-8', 'WINDOWS-1251', $text); return $text; } function __construct($login, $password, $url) { $this->userAgent = $_SERVER['HTTP_USER_AGENT']; $this->login = $login; $this->password = $password; $this->url = $url; } private function curl($url, $post = false) { $curl = curl_init($url); curl_setopt($curl, CURLOPT_COOKIEJAR, 'CookFile'); curl_setopt($curl, CURLOPT_COOKIEFILE, 'CookFile'); curl_setopt($curl, CURLOPT_USERAGENT, $this->userAgent); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 10); if ($post) { curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $post); } $res = curl_exec($curl); curl_close($curl); return $res; } function run() { $this->responce = $this->utfToWin($this->curl('http://ask.fm')); return $this; } public function getResponse() { return $this->responce; } } $ask = new Ask('login', 'pass', 'http://ask.fm'); var_dump( $ask->run()->getResponse()); 

Well, there seems to be a token in the <meta name="csrf-token" content="P1ZQiHqz3EBcnLCXqYIsvUI+dfjO6gnOAzlpigRgPgooZbzMVakLW5PgmRhRS82c3kKmRLl9AM4P/3xFPmdMYA==" />

  • I thank you for the answer, but my code started with an error and nothing happened :( - ikerya
  • I tried the homepage of ask.fm - Kostiantyn Okhotnyk
  • what mistake? ... - Kostiantyn Okhotnyk