Advertisement
Guest User

Untitled

a guest
Sep 17th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1. public function auto_login($userName = null, $userPassword = null ){
  2.         //CURLOPT_COOKIEJAR
  3.         $this->load->library('Curl');
  4.         //post values
  5.         $a_post = array(
  6.           'usr' => $userName,
  7.           'pwd' => $userPassword
  8.         );
  9.         $cookiesFile = $_SERVER['DOCUMENT_ROOT'].'/myCookies.txt';
  10.         $handle = fopen($cookiesFile, 'w+');
  11.         fclose($handle);
  12.  
  13.         $params = array(
  14.           CURLOPT_HEADER => 1,
  15.           CURLOPT_FOLLOWLOCATION => 1,
  16.           CURLOPT_COOKIEJAR => $_SERVER['DOCUMENT_ROOT'].'/myCookies.txt',
  17.           CURLOPT_COOKIEFILE => $_SERVER['DOCUMENT_ROOT'].'/myCookies.txt'
  18.         );
  19.  
  20.         $url = $this->config->item('ma_url').'?module=system&action=login';
  21.         $response = $this->curl->simple_post($url, $a_post,$params);
  22.         //$this->curl->debug();
  23.         $lines = explode("\n", $response);
  24.         foreach($lines as $l){
  25.           if(preg_match("/Set-Cookie/", $l)){
  26.                 $regCookie = $l;
  27.           }
  28.         }
  29.  
  30.  
  31.         header($regCookie);
  32.         header('location: '.$this->config->item('ma_url').'?module=management&action=view_account');
  33.        
  34.         //unlink($cookiesFile);
  35.  
  36.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement