Advertisement
Guest User

Untitled

a guest
Jun 30th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.67 KB | None | 0 0
  1. <?php
  2. /**
  3.  * This code for unpaid test only
  4.  *
  5.  * Please replace missng parts by your code
  6.  *
  7.  */
  8.  
  9. class Freelancer
  10. {
  11.  
  12.     public $user;
  13.     public $password;
  14.  
  15.     protected $token;
  16.     protected $csrf;
  17.  
  18.     protected function generateCSRF($length = 64) {
  19.         $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  20.         $charactersLength = strlen($characters);
  21.         $randomString = '';
  22.         for ($i = 0; $i < $length; $i++) {
  23.             $randomString .= $characters[rand(0, $charactersLength - 1)];
  24.         }
  25.         return $randomString;
  26.     }
  27.  
  28.     public function __construct()
  29.     {
  30.         $this->csrf = $this->generateCSRF();
  31.     }
  32.  
  33.     public function Login()
  34.     {
  35.         $login_url = 'https://www.freelancer.com/ajax/login.php';
  36.         $fields = [
  37.             'username' => $this->user,
  38.             'passwd' => $this->password,
  39.             'savelogin' => 'on',
  40.             'fromHomePage' => 'true',
  41.             'csrf_token' => $this->csrf
  42.         ];
  43.         $headers = [
  44.             "x-xsrf-token:$this->csrf",
  45.             "x-requested-with:XMLHttpRequest",
  46.             ":authority:www.freelancer.com",
  47.             ":method:POST",
  48.             ":path:/ajax/login.php",
  49.             ":scheme:https",
  50.             "content-type:application/x-www-form-urlencoded; charset=UTF-8",
  51.             "origin:https://www.freelancer.com",
  52.             "referer:https://www.freelancer.com",
  53.             "accept:application/json, text/javascript, */*; q=0.01",
  54.             "accept-language:en-US,en;q=0.8,ru;q=0.6,uk;q=0.4,fr;q=0.2",
  55.             "content-type:application/x-www-form-urlencoded; charset=UTF-8",
  56.             "cookie:XSRF-TOKEN=$this->csrf"
  57.         ];
  58.         $ch = curl_init();
  59.         curl_setopt($ch,CURLOPT_URL, $login_url);
  60.         curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
  61.         curl_setopt($ch,CURLOPT_POST, 1);
  62.         curl_setopt($ch,CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36");
  63.         curl_setopt($ch,CURLOPT_POSTFIELDS, $fields);
  64.         curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  65.         $result = curl_exec($ch);
  66.         echo "<pre>";
  67.         print_r($result);
  68.         curl_close($ch);
  69.     }
  70.  
  71.     public function isLogged()
  72.     {
  73.  
  74.         return true;
  75.  
  76.     }
  77.  
  78.  
  79. }
  80.  
  81. try {
  82.     $freelancerAPI = new Freelancer();
  83.     $freelancerAPI->user = 'someuser';
  84.     $freelancerAPI->password = 'somepass';
  85.     $freelancerAPI->Login();
  86.     $loginResult = $freelancerAPI->isLogged();
  87.  
  88.     echo "<pre>";
  89.     print_r($loginResult);exit;
  90.  
  91. } catch (Exception $e) {
  92.     echo $e->getMessage();
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement