Advertisement
Guest User

Untitled

a guest
May 4th, 2016
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. <?php
  2. class linkedInLogin {
  3. public function login(){
  4. $username = 'Email Here';
  5. $password = 'Password here';
  6. $csrf = $this->fetchCSRF();
  7. if($csrf == false){
  8. echo 'Error: loginCsrfParam fetching failed.';
  9. return;
  10. }
  11. //login form action url
  12. $url="https://www.linkedin.com/uas/login-submit";
  13. //$postinfo = "session_key=".$username."&session_password=".$password."&loginCsrfParam=".$csrf;
  14. $postfields = array('session_key' => $username, 'session_password' => $password, 'loginCsrfParam' => $csrf);
  15. $ch = curl_init();
  16. curl_setopt($ch, CURLOPT_HEADER, false);
  17. curl_setopt($ch, CURLOPT_NOBODY, false);
  18. curl_setopt($ch, CURLOPT_URL, $url);
  19. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  20. curl_setopt($ch, CURLOPT_COOKIESESSION, true);
  21. curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
  22. curl_setopt($ch, CURLOPT_USERAGENT,
  23. "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
  24. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //@TODO change back: curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  25. curl_setopt($ch, CURLOPT_REFERER, 'https://www.linkedin.com/uas/login');
  26. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  27. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
  28. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  29. curl_setopt($ch, CURLOPT_POST, 1);
  30. curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
  31. echo curl_exec($ch);
  32. curl_close($ch);
  33. }
  34.  
  35. // Fetches the CSRF for login authentication
  36. private function fetchCSRF(){
  37. $url = 'https://linkedin.com/uas/login';
  38. $html = file_get_contents($url);
  39. $precsrf = (int) strpos($html, '<input type="hidden" name="loginCsrfParam" value="');
  40. $postcsrf = (int) strpos($html, '" id="loginCsrfParam-login">');
  41. $length = $postcsrf - $precsrf - 50; // The -50 / + 50 is to correct for: <input type="hidden" name="login...
  42. $csrf = substr($html, $precsrf + 50, $length);
  43. if($csrf == false){
  44. return false;
  45. }
  46. return $csrf;
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement