Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class linkedInLogin {
- public function login(){
- $username = 'Email Here';
- $password = 'Password here';
- $csrf = $this->fetchCSRF();
- if($csrf == false){
- echo 'Error: loginCsrfParam fetching failed.';
- return;
- }
- //login form action url
- $url="https://www.linkedin.com/uas/login-submit";
- //$postinfo = "session_key=".$username."&session_password=".$password."&loginCsrfParam=".$csrf;
- $postfields = array('session_key' => $username, 'session_password' => $password, 'loginCsrfParam' => $csrf);
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_HEADER, false);
- curl_setopt($ch, CURLOPT_NOBODY, false);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
- curl_setopt($ch, CURLOPT_COOKIESESSION, true);
- curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
- curl_setopt($ch, CURLOPT_USERAGENT,
- "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //@TODO change back: curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_REFERER, 'https://www.linkedin.com/uas/login');
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
- echo curl_exec($ch);
- curl_close($ch);
- }
- // Fetches the CSRF for login authentication
- private function fetchCSRF(){
- $url = 'https://linkedin.com/uas/login';
- $html = file_get_contents($url);
- $precsrf = (int) strpos($html, '<input type="hidden" name="loginCsrfParam" value="');
- $postcsrf = (int) strpos($html, '" id="loginCsrfParam-login">');
- $length = $postcsrf - $precsrf - 50; // The -50 / + 50 is to correct for: <input type="hidden" name="login...
- $csrf = substr($html, $precsrf + 50, $length);
- if($csrf == false){
- return false;
- }
- return $csrf;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement