本文整理匯總了PHP中Zend_Http_Client::getCookieJar方法的典型用法代碼示例。如果您正苦於以下問題:PHP Zend_Http_Client::getCookieJar方法的具體用法?PHP Zend_Http_Client::getCookieJar怎麽用?PHP Zend_Http_Client::getCookieJar使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend_Http_Client
的用法示例。
在下文中一共展示了Zend_Http_Client::getCookieJar方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: login
public static function login($request)
{
$blogPath = SJB_Settings::getSettingByName('blog_path');
if (empty($blogPath)) {
return;
}
$username = $request['username'];
$password = $request['password'];
$userInfo = SJB_UserManager::getUserInfoByUserName($username);
$userInfo = $userInfo ? base64_encode(serialize($userInfo)) : false;
$url = SJB_System::getSystemSettings('SITE_URL') . $blogPath . '/wp-login.php';
$client = new Zend_Http_Client($url, array('useragent' => SJB_Request::getUserAgent(), 'maxredirects' => 0));
$client->setCookieJar();
$client->setCookie($_COOKIE);
$client->setMethod(Zend_Http_Client::POST);
$client->setParameterPost(array('log' => $username, 'pwd' => $password, 'noSJB' => 1, 'userInfo' => $userInfo, 'wp-submit' => 'Log in'));
try {
$response = $client->request();
foreach ($response->getHeaders() as $key => $header) {
if ('set-cookie' == strtolower($key)) {
if (is_array($header)) {
foreach ($header as $val) {
header("Set-Cookie: " . $val, false);
}
} else {
header("Set-Cookie: " . $header, false);
}
}
}
$_SESSION['wp_cookie_jar'] = @serialize($client->getCookieJar());
} catch (Exception $ex) {
}
}
示例2: shutdownHttpClient
public function shutdownHttpClient(Zend_Http_Client $httpClient)
{
if (!isset($this->_restSession)) {
$this->_restSession = new Zend_Session_Namespace('App_Rest_Service_' . $this->getRestService()->getServiceName() . '_Session');
}
$this->_restSession->cookieJar = $httpClient->getCookieJar();
}
示例3: testUnsetCookieJar
/**
* Test we can unset a cookie jar
*
*/
public function testUnsetCookieJar()
{
// Set the cookie jar just like in testSetNewCookieJar
$this->client->setCookieJar();
$this->client->setCookie('cookie', 'value');
$this->client->setCookie('chocolate', 'chips');
$jar = $this->client->getCookieJar();
// Try unsetting the cookiejar
$this->client->setCookieJar(null);
$this->assertNull($this->client->getCookieJar(), 'Cookie jar is expected to be null but it is not');
}
示例4: _request
/**
*
* @param string $url
* @param array $param
* @param string $method
* @return string
*/
protected function _request($url, $param = array(), $method = Zend_Http_Client::POST)
{
if ($this->_client === null) {
$config = array('useragent' => 'Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/44.0', 'encodecookies' => false, 'timeout' => 180);
$this->_client = new Zend_Http_Client($url, $config);
$this->_client->setCookieJar();
}
$this->_client->resetParameters()->setUri($url);
if (count($param['post']) > 0) {
foreach ($param['post'] as $name => $value) {
$this->_client->setParameterPost($name, $value);
}
}
if (count($param['get']) > 0) {
foreach ($param['get'] as $name => $value) {
$this->_client->setParameterPost($name, $value);
}
}
if (count($param['file']) > 0) {
foreach ($param['file'] as $name => $value) {
$this->_client->setFileUpload($value, $name);
}
}
if (count($param['cookie']) > 0) {
foreach ($param['cookie'] as $name => $value) {
$this->_client->setCookie($name, $value);
}
}
if (count($this->_cookies) > 0) {
foreach ($this->_cookies as $cookie) {
$this->_client->setCookie($cookie);
}
}
$response = $this->_client->request($method);
$this->_cookies = $this->_client->getCookieJar()->getAllCookies();
return $response->getBody();
}
示例5: getPlayableInfos
/**
* get an array with standard information about the playable
* @param string $url the hoster page or resource ID
* @param boolean $isId
* @return array format:
* array(
* 'title' => TITLE
* 'description' => DESCRIPTION
* 'length' => LENGTH
* ...
* )
*/
function getPlayableInfos($url, $isId = true)
{
if (!$isId) {
$url = $this->getResourceId($url);
}
// use cached values
if (array_key_exists($url, $this->info_cache)) {
return $this->info_cache[$url];
}
$http = new Zend_Http_Client("http://www.dailymotion.com/video/" . $url, array('headers' => array('User-Agent' => "vlc-shares/" . X_VlcShares::VERSION . " dailymotion/" . X_VlcShares_Plugins_DailyMotion::VERSION)));
$http->setCookieJar(true);
$http->getCookieJar()->addCookie(new Zend_Http_Cookie('family_filter', 'off', 'www.dailymotion.com'));
$datas = $http->request()->getBody();
if (preg_match('/<title>(.*)404(.*)<\\/title>/', $datas)) {
throw new Exception("Invalid ID {{$url}}", self::E_ID_INVALID);
}
$matches = array();
if (!preg_match('/\\.addVariable\\(\\"sequence\\", \\"(?P<sequence>.*?)\\"/', $datas, $matches)) {
throw new Exception("Invalid ID {{$url}}, sequence not found", self::E_ID_INVALID);
}
$sequence = urldecode($matches['sequence']);
$matches = array();
if (!preg_match('/videotitle\\=(?P<title>[^&]+)&/', $sequence, $matches)) {
$title = "";
}
$title = urldecode($matches['title']);
$matches = array();
if (!preg_match('/\\"videoDescription\\"\\:\\"(?P<description>[^\\"]*)\\"/', $sequence, $matches)) {
$description = '';
}
$description = urldecode($matches['description']);
$matches = array();
if (!preg_match('/\\"duration\\"\\:(?P<length>.*)\\,/', $sequence, $matches)) {
$length = '';
}
$length = $matches['length'];
$thumbnail = "http://www.dailymotion.com/thumbnail/320x240/video/{$url}";
$matches = array();
if (!preg_match('/\\"sdURL\\"\\:\\"(?P<video>[^\\"]+)\\"/', $sequence, $matches)) {
$video = '';
}
$video = stripslashes($matches['video']);
$infos = array('title' => $title, 'description' => $description, 'length' => $length, 'thumbnail' => $thumbnail, 'url' => $video);
// add in cache
$this->info_cache[$url] = $infos;
return $infos;
}
示例6: post
function post($url = null, $params = null, $config = array())
{
$_config = array();
$arrParams = array();
//-----------------
// Установим URL
if ($url) {
$this->client->setUri($url);
} else {
$url = $this->client->getUri(TRUE);
}
// Установим параметры запроса
if ($params) {
if (is_string($params)) {
// Преобразуем строку запроса в массив
parse_str($params, $arrParams);
$this->client->setParameterPost($arrParams);
} else {
$this->client->setParameterPost($params);
}
}
// Установим заголовок Referer
if (!empty($this->last_url)) {
$_config['headers']['Referer'] = $this->last_url;
}
// Запомним последний URL
$this->last_url = $url;
// Обьединим два массива
$config = $_config + $config;
// Сохраним последнюю конфигурацию
$this->last_config = $this->_setConfig($config);
// Выполним запрос
$response = $this->client->request("POST");
$html = $response->getBody();
// Запомним последний запрос в виде строки
$this->last_request = $this->client->getLastRequest();
// Запомним последний запрос в виде Zend_Http_Response
$this->last_response = $this->client->getLastResponse();
// Запомним последние полученные Сookies
$this->last_cookies = $this->client->getCookieJar()->getAllCookies();
return new PGPage($this->client->getUri(TRUE), $this->clean($html), $this);
}
示例7: fetch
protected function fetch($url, $retry = true)
{
if ($this->options->get('username', '') == '' || $this->options->get('password', '') == '') {
X_Debug::e("Account missing");
return false;
}
$http = new Zend_Http_Client();
$http->setCookieJar(true);
// load cookies from file
try {
/* @var $cacheHelper X_VlcShares_Plugins_Helper_Cache */
$cacheHelper = X_VlcShares_Plugins::helpers()->helper('cache');
$cookies = unserialize($cacheHelper->retrieveItem("realdebrid::cookies"));
X_Debug::i("Using cached authentication");
foreach ($cookies as $c) {
$_c = new Zend_Http_Cookie($c['name'], $c['value'], $c['domain'], $c['exp'], $c['path']);
$http->getCookieJar()->addCookie($_c);
}
} catch (Exception $e) {
// no cache plugin or no authentication performed
// perform a new authentication
X_Debug::i("Authentication required: {$e->getMessage()}");
try {
$http->setUri(sprintf(self::API_URL_LOGIN, $this->options->get('username'), md5($this->options->get('password')), time()));
$loginBody = Zend_Json::decode($http->request()->getBody());
} catch (Exception $e) {
if ($retry) {
X_Debug::e("Login request failed, try again: {$e->getMessage()}");
return $this->fetch($url, false);
} else {
X_Debug::e("Login request failed (2nd time): {$e->getMessage()}");
throw $e;
}
}
if ($loginBody['error'] != 0) {
// invalid login info
throw new Exception("Invalid Real-Debrid account");
} else {
X_Debug::i("Authentication performed, valid account");
// login ok, store information in cache (try)
try {
/* @var $cacheHelper X_VlcShares_Plugins_Helper_Cache */
$cacheHelper = X_VlcShares_Plugins::helpers()->helper('cache');
$cks = $http->getCookieJar()->getAllCookies(Zend_Http_CookieJar::COOKIE_OBJECT);
$minValidity = 99999999999;
foreach ($cks as $i => $c) {
/* @var $c Zend_Http_Cookie */
$expire = $c->getExpiryTime();
if ($expire != null && $expire < $minValidity) {
$minValidity = $expire;
}
$cks[$i] = array('domain' => $c->getDomain(), 'exp' => $c->getExpiryTime(), 'name' => $c->getName(), 'path' => $c->getPath(), 'value' => $c->getValue());
}
$minValidity = (int) ($minValidity - time() / 60) - 1;
if ($minValidity < 0) {
$minValidity = 5;
}
// if error, set to 5 minutes
// perform a new authentication every 7 days
$cacheHelper->storeItem("realdebrid::cookies", serialize($cks), $minValidity);
} catch (Exception $e) {
X_Debug::e("Real Debrid requires cache plugin, but it's disabled!!!");
}
}
}
$url = urlencode($url);
$url = sprintf(self::API_URL_FETCH, $url, time());
X_Debug::i("Fetching: {$url}");
$http->setUri($url)->setHeaders(array('User-Agent: vlc-shares/' . X_VlcShares::VERSION . ' realdebrid/' . X_VlcShares_Plugins_RealDebrid::VERSION));
// always add "showlink=1" and "lang=en" in the cookies
//$http
//->setCookie('showlink', '1')
//->setCookie('lang','en');
$links = $http->request()->getBody();
//X_Debug::i("Request: ".var_export( $http->getLastRequest() , true));
//X_Debug::i("Real debrid response: ".$links);
$json = Zend_Json::decode($links);
if (isset($json['error'])) {
switch ($json['error']) {
case '0':
// everything ok
break;
case '2':
// invalid login
// invalid account or login missing.
// Try 1 more time only forcing relogin
if ($retry) {
return $this->fetch($url, false);
} else {
return false;
}
case '5':
// expired account
return false;
default:
// maybe invalid links?
return false;
}
}
$links = array();
//.........這裏部分代碼省略.........
示例8: videoAction
public function videoAction()
{
$id = $this->getRequest()->getParam("id", false);
if (!$id) {
throw new Exception(X_Env::_("p_veoh_invalid_id"));
}
// this algorithm is taken from jdownload veoh hoster plugin
$http1 = new Zend_Http_Client();
$http1->setCookieJar(true);
$http1->setUri("http://www.veoh.com/watch/{$id}");
$response1 = $http1->request()->getBody();
$fbsettingPattern = '/FB\\.init\\(\\"(?P<fbsetting>[^\\"]+)\\"/';
$fbsetting = array();
if (!preg_match($fbsettingPattern, $response1, $fbsetting)) {
X_Debug::e("Can't get FBSetting. Regex failed");
throw new Exception("Can't get FBSetting");
}
$fbsetting = $fbsetting['fbsetting'];
$http2 = new Zend_Http_Client();
$http2->setUri("http://www.veoh.com/static/swf/webplayer/VWPBeacon.swf?port=50246&version=1.2.2.1112");
$response2 = $http2->request();
$http1->setUri("http://www.veoh.com/rest/v2/execute.xml?apiKey=" . base64_decode(X_VlcShares_Plugins_Veoh::APIKEY) . "&method=veoh.video.findByPermalink&permalink=" . $id . "&");
$response1 = $http1->request()->getBody();
$fHashPath = array();
if (!preg_match('/fullHashPath\\=\\"(?P<fHashPath>[^\\"]+)\\"/', $response1, $fHashPath)) {
X_Debug::e("Can't get fHashPath. Regex failed");
throw new Exception("Can't get fHashPath");
}
$fHashPath = $fHashPath['fHashPath'];
$fHashToken = array();
if (!preg_match('/fullHashPathToken\\=\\"(?P<fHashToken>[^\\"]+)\\"/', $response1, $fHashToken)) {
X_Debug::e("Can't get fHashToken. Regex failed");
throw new Exception("Can't get fHashToken");
}
$fHashToken = $fHashToken['fHashToken'];
// TODO check if correct
$fHashToken = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, pack('H*', base64_decode(X_VlcShares_Plugins_Veoh::SKEY)), base64_decode($fHashToken), MCRYPT_MODE_CBC, pack('H*', base64_decode(X_VlcShares_Plugins_Veoh::IV)));
//$fHashToken = trim($fHashToken);
if (!preg_match('/(?P<fHashToken>[a-z0-9A-z]+)/', $fHashToken, $fHashToken)) {
throw new Exception("Decryption failed");
}
$fHashToken = $fHashToken['fHashToken'];
if ($fHashPath == null || $fHashToken == null) {
throw new Exception("Hoster failure");
}
X_Debug::i("HashPath: {$fHashPath}, HashToken: {$fHashToken}");
$http1->getCookieJar()->addCookie(new Zend_Http_Cookie("fbsetting_{$fbsetting}", "%7B%22connectState%22%3A2%2C%22oneLineStorySetting%22%3A3%2C%22shortStorySetting%22%3A3%2C%22inFacebook%22%3Afalse%7D", "http://www.veoh.com"));
$http1->getCookieJar()->addCookie(new Zend_Http_Cookie("base_domain_{$fbsetting}", "veoh.com", "http://www.veoh.com"));
$cookies = $http1->getCookieJar()->getAllCookies(Zend_Http_CookieJar::COOKIE_STRING_CONCAT);
$opts = array('http' => array('header' => array("Referer: http://www.veoh.com/static/swf/qlipso/production/MediaPlayer.swf?version=2.0.0.011311.5", "x-flash-version: 10,1,53,64", "Cookie: {$cookies}"), 'content' => $fHashPath . $fHashToken));
$context = stream_context_create($opts);
X_Debug::i("Video url: {$fHashPath}{$fHashToken}");
// this action is so special.... no layout or viewRenderer
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->disableLayout();
// if user abort request (vlc/wii stop playing), this process ends
ignore_user_abort(false);
// close and clean the output buffer, everything will be read and send to device
ob_end_clean();
header("Content-Type: video/flv");
@readfile("{$fHashPath}{$fHashToken}", false, $context);
}
示例9: premiumAction
public function premiumAction()
{
// time to get params from get
/* @var $request Zend_Controller_Request_Http */
$request = $this->getRequest();
if (!$this->plugin->config('premium.enabled', true) || $this->plugin->config('premium.username', '') == '' || $this->plugin->config('premium.password', '') == '') {
throw new Exception(X_Env::_('p_megavideo_err_premiumdisabled'));
}
X_Debug::i('Premium account support enabled');
$videoId = $request->getParam('v', false);
// video file url
$qualityType = $request->getParam('q', X_VlcShares_Plugins_Helper_Megavideo::QUALITY_NORMAL);
// video file url
if ($videoId === false) {
// invalid request
throw new Exception(X_Env::_('p_megavideo_err_invalidrequest'));
return;
}
X_Debug::i("Video: {$videoId}");
// i check for NOPREMIUM quality: i don't need authentication in NOPREMIUM mode
if ($qualityType != X_VlcShares_Plugins_Helper_Megavideo::QUALITY_NOPREMIUM) {
X_Debug::i('Premium features enabled');
$http = new Zend_Http_Client('http://localhost/', array('maxredirects' => 10, 'timeout' => 10, 'keepalive' => true));
$http->setHeaders(array('User-Agent: Mozilla/5.0 (X11; Linux i686; rv:2.0.1) Gecko/20101019 Firefox/4.0.1', 'Accept-Language:it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4'));
$jarFile = APPLICATION_PATH . '/../data/megavideo/cookie.jar';
$ns = new Zend_Session_Namespace(__CLASS__);
if ($this->jar == null) {
if (false && isset($ns->jar) && $ns->jar instanceof Zend_Http_CookieJar) {
$this->jar = $ns->jar;
X_Debug::i('Loading stored authentication in Session');
} elseif (file_exists($jarFile)) {
$this->jar = new Zend_Http_CookieJar();
$cookies = unserialize(file_get_contents($jarFile));
foreach ($cookies as $c) {
$_c = new Zend_Http_Cookie($c['name'], $c['value'], $c['domain'], $c['exp'], $c['path']);
$this->jar->addCookie($_c);
}
X_Debug::i('Loading stored authentication in File');
} else {
$this->jar = new Zend_Http_CookieJar();
//$this->jar->addCookie(new Zend_Http_Cookie('l', 'it', 'http://www.megavideo.com'));
}
}
$http->setCookieJar($this->jar);
$userId = false;
if ($http->getCookieJar() != null) {
//X_Debug::i(var_export($http->getCookieJar()->getAllCookies(Zend_Http_CookieJar::COOKIE_STRING_ARRAY), true));
//$userId = $http->getCookieJar()->getCookie($cookieUri, 'user', Zend_Http_CookieJar::COOKIE_STRING_ARRAY);
$userId = $this->_getMatchCookieValue('user', 'http://www.megavideo.com/', $http->getCookieJar());
X_Debug::i("First check for userId: {$userId}");
}
if ($userId == false) {
X_Debug::i("No valid userId found in Cookies");
$this->_authenticateHttp($http, $this->plugin->config('premium.username', ''), $this->plugin->config('premium.password', ''));
//X_Debug::i(var_export($http->getCookieJar()->getAllCookies(Zend_Http_CookieJar::COOKIE_STRING_ARRAY), true));
//$userId = $http->getCookieJar()->getCookie($cookieUri, 'user', Zend_Http_CookieJar::COOKIE_STRING_ARRAY);
$userId = $this->_getMatchCookieValue('user', 'http://www.megavideo.com/', $http->getCookieJar());
if ($userId == false) {
X_Debug::f("Invalid account given");
throw new Exception(X_Env::_('p_megavideo_invalidaccount'));
}
}
X_Debug::i("UserId in cookies: {$userId}");
$uri = "http://www.megavideo.com/xml/player_login.php?u={$userId}&v={$videoId}";
$http->setUri($uri);
$response = $http->request();
$htmlString = $response->getBody();
if (strpos($htmlString, 'type="premium"') === false) {
X_Debug::w("Account isn't premium or not authenticated");
X_Debug::i(var_export($htmlString));
// invalid cookies
// need to re-authenticate
$this->_authenticateHttp($http, $this->plugin->config('premium.username', ''), $this->plugin->config('premium.password', ''));
$response = $http->request();
$htmlString = $response->getBody();
if (strpos($htmlString, 'type="premium"') === false) {
X_Debug::f("Invalid premium account");
X_Debug::i(var_export($htmlString));
throw new Exception(X_Env::_('p_megavideo_invalidpremiumaccount'));
}
}
// time to store the cookie
$this->jar = $http->getCookieJar();
// store the cookiejar
$cks = $this->jar->getAllCookies(Zend_Http_CookieJar::COOKIE_OBJECT);
foreach ($cks as $i => $c) {
/* @var $c Zend_Http_Cookie */
$cks[$i] = array('domain' => $c->getDomain(), 'exp' => $c->getExpiryTime(), 'name' => $c->getName(), 'path' => $c->getPath(), 'value' => $c->getValue());
}
if (@file_put_contents($jarFile, serialize($cks), LOCK_EX) === false) {
X_Debug::e('Error while writing jar file. Check permissions. Everything will work, but much more slower');
}
// in htmlString we should have an xml like this one:
/*
<?xml version="1.0" encoding="UTF-8"?>
<user type="premium" user="XXXXX" downloadurl="http%3A%2F%2Fwww444.megavideo.com%2Ffiles%2Fd9ab7ef6313e55ab26240f2aac9dd74f%2FAmerican.Dad.-.1AJN08.-.Tutto.su.Steve.%28All.About.Steve%29.-.DVDMuX.BY.Pi3TRo.%26amp%3B.yodonvito.avi" />
*/
// i create context here so i can use the same context
// for normal link quality video
$cookies = $http->getCookieJar()->getAllCookies(Zend_Http_CookieJar::COOKIE_STRING_CONCAT);
//.........這裏部分代碼省略.........
示例10: _loadPage
private function _loadPage($uri, $forceAuth = false)
{
X_Debug::i("Loading page {$uri}");
$http = new Zend_Http_Client($uri, array('maxredirects' => $this->config('request.maxredirects', 10), 'timeout' => $this->config('request.timeout', 10), 'keepalive' => true));
$http->setHeaders(array('User-Agent: vlc-shares/' . X_VlcShares::VERSION . ' animeftw/' . self::VERSION));
$jarFile = APPLICATION_PATH . '/../data/animeftw/cookie.jar';
$ns = new Zend_Session_Namespace(__CLASS__);
if ($this->jar == null) {
if (false && isset($ns->jar) && $ns->jar instanceof Zend_Http_CookieJar) {
$this->jar = $ns->jar;
X_Debug::i('Loading stored authentication in Session');
} elseif (file_exists($jarFile)) {
if (filectime($jarFile) < time() - 24 * 60 * 60) {
X_Debug::i('Jarfile is old. Refreshing it');
@unlink($jarFile);
} else {
$this->jar = new Zend_Http_CookieJar();
$cookies = unserialize(file_get_contents($jarFile));
foreach ($cookies as $c) {
$_c = new Zend_Http_Cookie($c['name'], $c['value'], $c['domain'], $c['exp'], $c['path']);
$this->jar->addCookie($_c);
}
X_Debug::i('Loading stored authentication in File');
}
}
}
$http->setCookieJar($this->jar);
$response = $http->request();
$htmlString = $response->getBody();
if ($forceAuth && $this->config('auth.username', '') != '' && $this->config('auth.password', '') != '' && !$this->_isAuthenticated($htmlString)) {
X_Debug::i("Autentication needed");
$http->setCookieJar(true);
$pageLogin = $this->config('login.url', self::PAGE_LOGIN);
$http->setUri($pageLogin);
$http->setParameterPost(array('username' => (string) $this->config('auth.username', ''), 'password' => (string) $this->config('auth.password', ''), '_submit_check' => '1', 'submit' => 'Sign In', 'remember' => 'on', 'last_page' => 'https://www.animeftw.tv'));
// TODO remove this
if (APPLICATION_ENV == 'development') {
$response = $http->request(Zend_Http_Client::POST);
if (!$this->_isAuthenticated($response->getBody())) {
X_Debug::w('Wrong credentials or authentication procedure doesn\'t work');
} else {
X_Debug::w('Client authenticated. Full access granted');
}
//X_Debug::i($response->getBody());
} else {
$http->request(Zend_Http_Client::POST);
}
$this->jar = $http->getCookieJar();
// store the cookiejar
$cks = $this->jar->getAllCookies(Zend_Http_CookieJar::COOKIE_OBJECT);
foreach ($cks as $i => $c) {
/* @var $c Zend_Http_Cookie */
$cks[$i] = array('domain' => $c->getDomain(), 'exp' => $c->getExpiryTime(), 'name' => $c->getName(), 'path' => $c->getPath(), 'value' => $c->getValue());
}
if (@file_put_contents($jarFile, serialize($cks), LOCK_EX) === false) {
X_Debug::e('Error while writing jar file. Check permissions. Everything will work, but much more slower');
}
//$ns->jar = $this->jar;
// time to do a new old request
//$http->resetParameters();
$http->setUri($uri);
$response = $http->request(Zend_Http_Client::GET);
$htmlString = $response->getBody();
}
return $htmlString;
}
示例11: _loadPage
private function _loadPage($uri, $forceAuth = false)
{
X_Debug::i("Loading page {$uri}");
$http = new Zend_Http_Client($uri, array('maxredirects' => $this->config('request.maxredirects', 10), 'timeout' => $this->config('request.timeout', 10), 'keepalive' => true));
$http->setHeaders(array($this->config('hide.useragent', false) ? 'User-Agent: vlc-shares/' . X_VlcShares::VERSION : 'User-Agent: Mozilla/5.0 (X11; Linux i686; rv:2.0.1) Gecko/20101019 Firefox/4.0.1'));
$jarFile = APPLICATION_PATH . '/../data/animedb/cookie.jar';
$ns = new Zend_Session_Namespace(__CLASS__);
if ($this->jar == null) {
if (false && isset($ns->jar) && $ns->jar instanceof Zend_Http_CookieJar) {
$this->jar = $ns->jar;
X_Debug::i('Loading stored authentication in Session');
} elseif (file_exists($jarFile)) {
$this->jar = new Zend_Http_CookieJar();
$cookies = unserialize(file_get_contents($jarFile));
foreach ($cookies as $c) {
$_c = new Zend_Http_Cookie($c['name'], $c['value'], $c['domain'], $c['exp'], $c['path']);
$this->jar->addCookie($_c);
}
X_Debug::i('Loading stored authentication in File');
}
}
$http->setCookieJar($this->jar);
//time to make the request
$response = $http->request();
$htmlString = $response->getBody();
//X_Debug::i($htmlString);
// before return the page, I have to check if i'm authenticated
// TODO REMOVE AUTH
if ($forceAuth && $this->config('auth.username', '') != '' && $this->config('auth.password', '') != '' && !$this->_isAuthenticated($htmlString)) {
X_Debug::i("Autentication needed");
$token = $this->_getSecurityToken($htmlString);
//$sValue = $this->_getSValue($htmlString);
// do new login
$http->setCookieJar(true);
$pageLogin = $this->config('login.url', 'http://animedb.tv/forum/login.php?do=login');
$http->setUri($pageLogin);
$http->setParameterPost(array('vb_login_username' => (string) $this->config('auth.username', ''), 'vb_login_password' => (string) $this->config('auth.password', ''), 'vb_login_password_hint' => 'Password', 'vb_login_md5password' => '', 'vb_login_md5password_utf' => '', 'securitytoken' => $token, 'do' => 'login', 'cookieuser' => 1, 's' => '', 'x' => 13, 'y' => 30));
// TODO remove this
if (APPLICATION_ENV == 'development') {
$response = $http->request(Zend_Http_Client::POST);
if (!$this->_isAuthenticated($response->getBody(), '<p class="blockrow restore">Grazie per esserti collegato,')) {
X_Debug::w('Wrong credentials or authentication procedure doesn\'t work');
} else {
X_Debug::w('Client authenticated. Full access granted');
}
//X_Debug::i($response->getBody());
} else {
$http->request(Zend_Http_Client::POST);
}
$this->jar = $http->getCookieJar();
// store the cookiejar
$cks = $this->jar->getAllCookies(Zend_Http_CookieJar::COOKIE_OBJECT);
foreach ($cks as $i => $c) {
/* @var $c Zend_Http_Cookie */
$cks[$i] = array('domain' => $c->getDomain(), 'exp' => $c->getExpiryTime(), 'name' => $c->getName(), 'path' => $c->getPath(), 'value' => $c->getValue());
}
if (@file_put_contents($jarFile, serialize($cks), LOCK_EX) === false) {
X_Debug::e('Error while writing jar file. Check permissions. Everything will work, but much more slower');
}
//$ns->jar = $this->jar;
// time to do a new old request
//$http->resetParameters();
$http->setUri($uri);
$response = $http->request(Zend_Http_Client::GET);
$htmlString = $response->getBody();
//X_Debug::i($htmlString);
}
return $htmlString;
}
示例12: _loadPage
private function _loadPage($uri)
{
X_Debug::i("Loading page {$uri}");
$http = new Zend_Http_Client($uri, array('maxredirects' => $this->config('request.maxredirects', 10), 'timeout' => $this->config('request.timeout', 10), 'keepalive' => true));
$http->setHeaders(array($this->config('hide.useragent', false) ? 'User-Agent: vlc-shares/' . X_VlcShares::VERSION : 'User-Agent: Mozilla/5.0 (X11; Linux i686; rv:2.0.1) Gecko/20101019 Firefox/4.0.1', 'X-Requested-With: XMLHttpRequest', 'Referer: http://www.opfitalia.net/mediacenter/index.php?page=show_streaming', 'Content-Type: application/x-www-form-urlencoded'));
$jarFile = APPLICATION_PATH . '/../data/opfitalia/cookie.jar';
//$ns = new Zend_Session_Namespace(__CLASS__);
if ($this->jar == null) {
// Session disabled, i'm not sure wiimc can handle sessions
/*if ( false && isset($ns->jar) && $ns->jar instanceof Zend_Http_CookieJar ) {
$this->jar = $ns->jar;
X_Debug::i('Loading stored authentication in Session');
} else*/
if (file_exists($jarFile)) {
$this->jar = new Zend_Http_CookieJar();
$cookies = unserialize(file_get_contents($jarFile));
foreach ($cookies as $c) {
$_c = new Zend_Http_Cookie($c['name'], $c['value'], $c['domain'], $c['exp'], $c['path']);
$this->jar->addCookie($_c);
}
X_Debug::i('Loading stored authentication in File');
} else {
X_Debug::i('No cookie file');
}
}
$http->setCookieJar($this->jar);
//time to make the request
$response = $http->request();
$jsonString = $response->getBody();
try {
$decoded = Zend_Json::decode($jsonString, Zend_Json::TYPE_OBJECT);
return $decoded;
} catch (Exception $e) {
// if the request doesn't return JSON code,
// maybe user isn't authenticated
X_Debug::i('User not authenticated');
if ($this->config('auth.username', '') != '' && $this->config('auth.password', '') != '') {
X_Debug::i("Autentication needed");
// do new login
$http->setCookieJar(true);
$pageLogin = $this->config('login.url', 'http://www.opfitalia.net/mediacenter/index.php?page=login');
$http->setUri($pageLogin);
// TODO remove this
$http->setParameterPost(array('username' => (string) $this->config('auth.username', ''), 'password' => (string) hash('sha256', $this->config('auth.password', ''), false), 'redirectUrl' => '', 'rememberMe' => '1'));
// TODO remove this
if (APPLICATION_ENV == 'development') {
$response = $http->request(Zend_Http_Client::POST);
if (!$this->_isAuthenticated($response->getBody(), 'correttamente')) {
X_Debug::w('Wrong credentials or authentication procedure doesn\'t work');
} else {
X_Debug::w('Client authenticated. Full access granted');
}
//X_Debug::i($response->getBody());
} else {
$http->request(Zend_Http_Client::POST);
}
$this->jar = $http->getCookieJar();
// store the cookiejar
$cks = $this->jar->getAllCookies(Zend_Http_CookieJar::COOKIE_OBJECT);
foreach ($cks as $i => $c) {
/* @var $c Zend_Http_Cookie */
$cks[$i] = array('domain' => $c->getDomain(), 'exp' => $c->getExpiryTime(), 'name' => $c->getName(), 'path' => $c->getPath(), 'value' => $c->getValue());
}
if (@file_put_contents($jarFile, serialize($cks), LOCK_EX) === false) {
X_Debug::e('Error while writing jar file. Check permissions. Everything will work, but much more slower');
}
//$ns->jar = $this->jar;
$http->setUri($uri);
$http->resetParameters(false);
$response = $http->request(Zend_Http_Client::GET);
$jsonString = $response->getBody();
try {
$decoded = Zend_Json::decode($jsonString, Zend_Json::TYPE_OBJECT);
} catch (Exception $e) {
// epic fail
// Useless authentication
//X_Debug::i('Epic fail page: '.print_r($jsonString, true));
throw new Exception('Authetication failed');
}
} else {
throw new Exception('Username/Password not found');
}
}
return $decoded;
}
示例13: isAuthenticated
public function isAuthenticated()
{
return $this->request->getCookieJar()->getCookie('http://' . $this->config->getHost() . ':' . $this->config->getPort(), 'AuthSession') !== false;
}