Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * This code for unpaid test only
- *
- * Please replace missng parts by your code
- *
- */
- class Freelancer
- {
- public $user;
- public $password;
- protected $token;
- protected $csrf;
- public function generateCSRF($length = 64) {
- $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
- $charactersLength = strlen($characters);
- $randomString = '';
- for ($i = 0; $i < $length; $i++) {
- $randomString .= $characters[rand(0, $charactersLength - 1)];
- }
- return $randomString;
- }
- public function __construct()
- {
- $this->csrf = $this->generateCSRF();
- }
- public function Login()
- {
- $login_url = 'https://www.freelancer.com/ajax/login.php';
- $fields = [
- 'username' => $this->user,
- 'passwd' => $this->password,
- 'savelogin' => 'on',
- 'fromHomePage' => 'true',
- 'csrf_token' => $this->csrf
- ];
- $headers = [
- "x-xsrf-token:$this->csrf",
- "x-requested-with:XMLHttpRequest",
- ":authority:www.freelancer.com",
- ":method:POST",
- ":path:/ajax/login.php",
- ":scheme:https",
- "content-type:application/x-www-form-urlencoded; charset=UTF-8",
- "origin:https://www.freelancer.com",
- "referer:https://www.freelancer.com",
- "accept:application/json, text/javascript, */*; q=0.01",
- "accept-language:en-US,en;q=0.8,ru;q=0.6,uk;q=0.4,fr;q=0.2",
- "content-type:application/x-www-form-urlencoded; charset=UTF-8",
- "cookie:XSRF-TOKEN=$this->csrf"
- ];
- $ch = curl_init();
- curl_setopt($ch,CURLOPT_URL, $login_url);
- curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch,CURLOPT_POST, 1);
- 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");
- curl_setopt($ch,CURLOPT_POSTFIELDS, $fields);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
- $result = curl_exec($ch);
- echo "<pre>";
- print_r($result);
- curl_close($ch);
- }
- public function isLogged()
- {
- return true;
- }
- }
- try {
- $freelancerAPI = new Freelancer();
- $freelancerAPI->user = 'someuser';
- $freelancerAPI->password = 'somepass';
- $freelancerAPI->Login();
- $loginResult = $freelancerAPI->isLogged();
- echo "<pre>";
- print_r($loginResult);exit;
- } catch (Exception $e) {
- echo $e->getMessage();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement