Example #1
0
 static function login($url = null, $user, $pass)
 {
     if (!function_exists('curl_init')) {
         return false;
     }
     @unlink(self::ojscookie);
     // form based auth
     if ($url !== null) {
         $content = self::get_content($url);
         preg_match('/<input.*wpLoginToken.*value="([a-f0-9]+)"/', $content, $matches);
         $token = $matches[1];
         preg_match('/<form.*userlogin.*action="(.+)"/', $content, $matches);
         $login_url = parse_url($url);
         $action = $login_url['scheme'] . '://' . $login_url['host'] . html_entity_decode($matches[1]);
         $user = urlencode($user);
         $postdata = "wpName={$user}&wpPassword={$pass}&wpRemember=1&wpLoginToken={$token}";
         return self::get_content($action, $postdata);
     } else {
         // http basic auth
         self::$options = array(CURLOPT_HTTPAUTH => CURLAUTH_ANY, CURLOPT_USERPWD => $user . ':' . $pass);
         return true;
     }
 }