public static function initialize() { if (self::$initialized) { return; } self::$initialized = true; try { // Initialize local session Session::init(); if (!empty($_GET['logout'])) { self::destroy(); Session::init(); } if (!Session::userIsLoggedIn() && Request::cookie('remember_me')) { if (!LoginModel::loginWithCookie(Request::cookie('remember_me'))) { LoginModel::deleteCookie(); } } $currentUrl = $_SERVER['REQUEST_URI']; $end = strpos($currentUrl, '?'); if ($end === false) { $end = strpos($currentUrl, '#'); } if ($end !== false) { $currentUrl = substr($currentUrl, 0, $end); } // Initialize Facebook session /*self::$facebookSession = new FacebookSessionWrapper( Tools::getBaseUrl() . $currentUrl, Tools::getBaseUrl() . '/logout/' );*/ } catch (\Exception $ex) { } }
function getCompleteTask() { $data = Request::cookie('auth'); $model = new siteUserTaskModel(); $tasks = $model->where(array('user' => $data['login'], 'status' => 0))->sort('date', -1)->fetchAll(); return $tasks; }
/** * Sends the HTTP message [Request] to a remote server and processes * the response. * * @param Request $request request to send * @param Response $request response to send * @return Response */ public function _send_message(Request $request, Response $response) { $http_method_mapping = array(HTTP_Request::GET => HTTPRequest::METH_GET, HTTP_Request::HEAD => HTTPRequest::METH_HEAD, HTTP_Request::POST => HTTPRequest::METH_POST, HTTP_Request::PUT => HTTPRequest::METH_PUT, HTTP_Request::DELETE => HTTPRequest::METH_DELETE, HTTP_Request::OPTIONS => HTTPRequest::METH_OPTIONS, HTTP_Request::TRACE => HTTPRequest::METH_TRACE, HTTP_Request::CONNECT => HTTPRequest::METH_CONNECT); // Create an http request object $http_request = new HTTPRequest($request->uri(), $http_method_mapping[$request->method()]); if ($this->_options) { // Set custom options $http_request->setOptions($this->_options); } // Set headers $http_request->setHeaders($request->headers()->getArrayCopy()); // Set cookies $http_request->setCookies($request->cookie()); // Set query data (?foo=bar&bar=foo) $http_request->setQueryData($request->query()); // Set the body if ($request->method() == HTTP_Request::PUT) { $http_request->addPutData($request->body()); } else { $http_request->setBody($request->body()); } try { $http_request->send(); } catch (HTTPRequestException $e) { throw new Request_Exception($e->getMessage()); } catch (HTTPMalformedHeaderException $e) { throw new Request_Exception($e->getMessage()); } catch (HTTPEncodingException $e) { throw new Request_Exception($e->getMessage()); } // Build the response $response->status($http_request->getResponseCode())->headers($http_request->getResponseHeader())->cookie($http_request->getResponseCookies())->body($http_request->getResponseBody()); return $response; }
public static function Logout() { setcookie('userid', '0', time() + 10, '/'); UserModel::update(['hash' => ''])->where('hash = ?', [0 => Request::cookie('userid')]); self::$login = '******'; self::$id = 0; self::$company_id = 0; }
public static function unsetCart() { $key = \Request::cookie('shoppingCart'); $cart = \App\Cart::where('key', $key)->first(); $cookie = \Cookie::forget('shoppingCart'); $cart->delete(); return $cookie; }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $cookie = \Request::cookie('remember_token'); if ($cookie && !\Session::has('User')) { $this->authService->autoLoginCheck(); } return $next($request); }
/** * Sends the HTTP message [Request] to a remote server and processes * the response. * * @param Request request to send * @return Response */ public function _send_message(Request $request) { // Response headers $response_headers = array(); // Set the request method $options[CURLOPT_CUSTOMREQUEST] = $request->method(); // Set the request body. This is perfectly legal in CURL even // if using a request other than POST. PUT does support this method // and DOES NOT require writing data to disk before putting it, if // reading the PHP docs you may have got that impression. SdF $options[CURLOPT_POSTFIELDS] = $request->body(); // Process headers if ($headers = $request->headers()) { $http_headers = array(); foreach ($headers as $key => $value) { $http_headers[] = $key . ': ' . $value; } $options[CURLOPT_HTTPHEADER] = $http_headers; } // Process cookies if ($cookies = $request->cookie()) { $options[CURLOPT_COOKIE] = http_build_query($cookies, NULL, '; '); } // Create response $response = $request->create_response(); $response_header = $response->headers(); // Implement the standard parsing parameters $options[CURLOPT_HEADERFUNCTION] = array($response_header, 'parse_header_string'); $this->_options[CURLOPT_RETURNTRANSFER] = TRUE; $this->_options[CURLOPT_HEADER] = FALSE; // Apply any additional options set to $options += $this->_options; $uri = $request->uri(); if ($query = $request->query()) { $uri .= '?' . http_build_query($query, NULL, '&'); } // Open a new remote connection $curl = curl_init($uri); // Set connection options if (!curl_setopt_array($curl, $options)) { throw new Request_Exception('Failed to set CURL options, check CURL documentation: :url', array(':url' => 'http://php.net/curl_setopt_array')); } // Get the response body $body = curl_exec($curl); // Get the response information $code = curl_getinfo($curl, CURLINFO_HTTP_CODE); if ($body === FALSE) { $error = curl_error($curl); } // Close the connection curl_close($curl); if (isset($error)) { throw new Request_Exception('Error fetching remote :url [ status :code ] :error', array(':url' => $request->url(), ':code' => $code, ':error' => $error)); } $response->status($code)->body($body); return $response; }
function __construct() { Session::init(); Auth::checkSessionConcurrency(); if (!Session::userIsLoggedIn() && Request::cookie('remember_me')) { Redirect::to("login/loginWithCookie"); } $this->view = new View(); }
public function loginWithCookie() { $success = LoginModel::loginWithCookie(Request::cookie('remember_me')); if ($success) { Redirect::to('dashboard/index'); } else { LoginModel::deleteCookie(); Redirect::to('login/index'); } }
public function logout() { $this->authService->unsetUser(); $token = \Request::cookie('remember_token'); if ($token) { $this->authService->deleteOldRememberToken($token); $this->authService->deleteRememberTokenCookie(); } return \Redirect::to('login'); }
/** * Construct the (base) controller. This happens when a real controller is constructed, like in * the constructor of IndexController when it says: parent::__construct(); */ function __construct() { // always initialize a session Session::init(); // user is not logged in but has remember-me-cookie ? then try to login with cookie ("remember me" feature) if (!Session::userIsLoggedIn() and Request::cookie('remember_me')) { header('location: ' . Config::get('URL') . 'login/loginWithCookie'); } // create a view object to be able to use it inside a controller, like $this->View->render(); $this->View = new View(); }
public function autoLoginCheck() { $token = \Request::cookie('remember_token'); if ($user = $this->userService->getByToken($token)) { $this->deleteOldRememberToken($token); $remember = true; $this->login($user, $remember); return true; } return false; }
/** * Construct the (base) controller. This happens when a real controller is constructed, like in * the constructor of IndexController when it says: parent::__construct(); */ function __construct() { // always initialize a session Session::init(); // user is not logged in but has remember-me-cookie ? then try to login with cookie ("remember me" feature) if (!Session::userIsLoggedIn() and Request::cookie('remember_me')) { header('location: ' . Config::get('URL') . 'login/loginWithCookie'); } // create a view object to be able to use it inside a controller, like $this->View->render(); $this->View = new View(); $this->Must = new MustView(array('loader' => new Mustache_Loader_FilesystemLoader(Config::get('PATH_VIEW'), ['extension' => '.html']), 'partials_loader' => new Mustache_Loader_FilesystemLoader(Config::get('PATH_PARTIAL'), ['extension' => '.html']), 'cache' => Config::get('PATH_TEMPLATES_CACHE'), 'logger' => new MustacheLogger(Mustache_Logger::DEBUG))); }
/** * Login with cookie */ public function loginWithCookie() { // run the loginWithCookie() method in the login-model, put the result in $login_successful (true or false) $login_successful = LoginModel::loginWithCookie(Request::cookie('remember_me')); // if login successful, redirect to dashboard/index ... if ($login_successful) { Redirect::to('dashboard/index'); } else { // if not, delete cookie (outdated? attack?) and route user to login form to prevent infinite login loops LoginModel::deleteCookie(); Redirect::to('login/index'); } }
public static function init() { if (ini_get('magic_quotes_gpc')) { self::$get = $_GET; self::$post = $_POST; } else { self::$get = $_GET = self::addSlashes($_GET); self::$post = $_POST = self::addSlashes($_POST); } self::$cookie = $_COOKIE; self::$file = $_FILES; self::$method = $_SERVER['REQUEST_METHOD']; }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $cookie = \Request::cookie('remember_token'); if ($cookie && !\Session::has('User')) { $this->authService->autoLoginCheck(); } // TODO: delete after release. $loginUser = $this->userService->getCurrentUser(); if (!empty($loginUser) && !isset($loginUser->role)) { $user = $this->userService->getById($loginUser->id); $this->authService->setUser($user); } return $next($request); }
public function testIndex() { $req = new Request('test/test', ['td1' => 'd1']); $this->assertEquals('test/test', $req->getRequestUri()); $this->assertEquals('d1', $req->td1); $this->assertTrue(isset($req->td1)); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; $this->assertTrue($req->isXmlHttpRequest()); $req->setParam('a', 1); $this->assertEquals(1, $req->a); $this->assertEquals(1, $req->env('q', 1)); $this->assertEquals(1, $req->cookie('q', 1)); $this->assertEquals(1, $req->server('q', 1)); $this->assertInstanceOf('Yagrysha\\MVC\\User', $req->user); }
function execute() { $userID = (int) Request::post('user'); $model = connectionUserModel::create(); $user = $model->where(array('id' => (int) $userID))->fetchOne(); if (isset($user['token'])) { Request::cookie('connection_user', $userID); Request::cookie('connection_token', $user['token']); } else { $now = (int) strtotime('now'); $token = md5($user['email'] . $user['date'] . $now); Request::cookie('connection_user', $userID); Request::cookie('connection_token', $token); $model->where(array('id' => $userID))->update(array('token' => $token)); } }
function loged() { $login = false; $password = false; $auth = Request::cookie('auth') ? Request::cookie('auth') : false; if (!$auth) { return false; } $login = $auth['login']; $password = $auth['password']; if ($login && $password) { $user = new User(); return $user->auth($login, $password); } return false; }
/** * Sends the HTTP message [Request] to a remote server and processes * the response. * * @param Request request to send * @return Response * @uses [PHP cURL](http://php.net/manual/en/book.curl.php) */ public function _send_message(Request $request) { // Calculate stream mode $mode = $request->method() === HTTP_Request::GET ? 'r' : 'r+'; // Process cookies if ($cookies = $request->cookie()) { $request->headers('cookie', http_build_query($cookies, NULL, '; ')); } // Get the message body $body = $request->body(); if (is_resource($body)) { $body = stream_get_contents($body); } // Set the content length $request->headers('content-length', (string) strlen($body)); list($protocol) = explode('/', $request->protocol()); // Create the context $options = array(strtolower($protocol) => array('method' => $request->method(), 'header' => (string) $request->headers(), 'content' => $body)); // Create the context stream $context = stream_context_create($options); stream_context_set_option($context, $this->_options); $uri = $request->uri(); if ($query = $request->query()) { $uri .= '?' . http_build_query($query, NULL, '&'); } $stream = fopen($uri, $mode, FALSE, $context); $meta_data = stream_get_meta_data($stream); // Get the HTTP response code $http_response = array_shift($meta_data['wrapper_data']); if (preg_match_all('/(\\w+\\/\\d\\.\\d) (\\d{3})/', $http_response, $matches) !== FALSE) { $protocol = $matches[1][0]; $status = (int) $matches[2][0]; } else { $protocol = NULL; $status = NULL; } // Create a response $response = $request->create_response(); $response_header = $response->headers(); // Process headers array_map(array($response_header, 'parse_header_string'), array(), $meta_data['wrapper_data']); $response->status($status)->protocol($protocol)->body(stream_get_contents($stream)); // Close the stream after use fclose($stream); return $response; }
public static function lang() { if (!is_null(self::$lang)) { return self::$lang; } self::$lang = self::$langDefault; if (Request::cookie(self::$langKeyCookie)) { $saveLang = Request::cookie(self::$langKeyCookie); } else { $saveLang = Request::getUserLang(); } $lang = array_map(function ($a) { return $a['iso']; }, Language::getList()); if (in_array($saveLang, $lang)) { self::$lang = $saveLang; } Request::cookie(self::$langKeyCookie, self::$lang); return self::$lang; }
private function __construct(Request $req) { $user = $req->session(static::SESSIONNAME); if ($user) { $this->userData = $user; } else { $code = $req->cookie(static::REMEMBER_COOKIENAME); if ($code) { $this->userData = $this->getUserDataByCode($code); } } if (empty($this->userData['id'])) { $this->userData = $this->defUserData; } else { $this->isLogged = true; } $this->userData['ip'] = $req->ip; $this->userData['tm'] = time(); $this->setSession(); }
public function addToCart($id, $number = 1) { if (\Request::cookie('shoppingCart')) { $cartData = shoppingCart::getCart(); $cart = unserialize($cartData->data); $cart->addToCart($id, $number); $sCart = serialize($cart); $cartData->data = $sCart; $cartData->save(); } else { $cart = new shoppingCart(); $cart->addToCart($id, $number); $sCart = serialize($cart); $ip = $_SERVER['REMOTE_ADDR']; $now = \Carbon\Carbon::now()->toDateTimeString(); $token = md5($ip . $now); \Cookie::queue('shoppingCart', $token); \App\Cart::create(['key' => $token, 'data' => $sCart]); } return redirect()->back(); }
function __construct() { // always initialize a session Session::init(); // user is not logged in but has remember-me-cookie ? then try to login with cookie ("remember me" feature) if (!Session::userIsLoggedIn() and Request::cookie('remember_me')) { header('location: ' . Config::get('URL') . 'login/loginWithCookie'); } /** * * add in Twig or use the Static Function * if use the Static method this is not needed here * * */ Twig_Autoloader::register(); $this->loader = new Twig_Loader_Filesystem(VIEW_DIR); $this->twig = new Twig_Environment($this->loader, array('cache' => APP_DIR . '/cache', 'debug' => true, 'auto_reload' => true, 'strict_variables' => true, 'autoescape' => true)); /** * the View is no longer needed */ // create a view object to be able to use it inside a controller, like $this->View->render(); //$this->View = new View(); }
public static function factory($uri = TRUE, $client_params = array(), $allow_external = TRUE, $injected_routes = array()) { if (!Request::$initial) { $protocol = HTTP::$protocol; if (isset($_SERVER['REQUEST_METHOD'])) { $method = $_SERVER['REQUEST_METHOD']; } else { $method = HTTP_Request::GET; } if (!empty($_SERVER['HTTPS']) and filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN) or isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' and in_array($_SERVER['REMOTE_ADDR'], Request::$trusted_proxies)) { $secure = TRUE; } if (isset($_SERVER['HTTP_REFERER'])) { $referrer = $_SERVER['HTTP_REFERER']; } if (isset($_SERVER['HTTP_USER_AGENT'])) { Request::$user_agent = $_SERVER['HTTP_USER_AGENT']; } if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) { $requested_with = $_SERVER['HTTP_X_REQUESTED_WITH']; } if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) and isset($_SERVER['REMOTE_ADDR']) and in_array($_SERVER['REMOTE_ADDR'], Request::$trusted_proxies)) { $client_ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); Request::$client_ip = array_shift($client_ips); unset($client_ips); } elseif (isset($_SERVER['HTTP_CLIENT_IP']) and isset($_SERVER['REMOTE_ADDR']) and in_array($_SERVER['REMOTE_ADDR'], Request::$trusted_proxies)) { $client_ips = explode(',', $_SERVER['HTTP_CLIENT_IP']); Request::$client_ip = array_shift($client_ips); unset($client_ips); } elseif (isset($_SERVER['REMOTE_ADDR'])) { // The remote IP address Request::$client_ip = $_SERVER['REMOTE_ADDR']; } if ($method !== HTTP_Request::GET) { // Ensure the raw body is saved for future use $body = file_get_contents('php://input'); } if ($uri === TRUE) { // Attempt to guess the proper URI $uri = Request::detect_uri(); } $cookies = array(); if ($cookie_keys = array_keys($_COOKIE)) { foreach ($cookie_keys as $key) { $cookies[$key] = Cookie::get($key); } } // Create the instance singleton Request::$initial = $request = new Request($uri, $client_params, $allow_external, $injected_routes); // Store global GET and POST data in the initial request only $request->protocol($protocol)->query($_GET)->post($_POST); if (isset($secure)) { // Set the request security $request->secure($secure); } if (isset($method)) { // Set the request method $request->method($method); } if (isset($referrer)) { // Set the referrer $request->referrer($referrer); } if (isset($requested_with)) { // Apply the requested with variable $request->requested_with($requested_with); } if (isset($body)) { // Set the request body (probably a PUT type) $request->body($body); } if (isset($cookies)) { $request->cookie($cookies); } } else { $request = new Request($uri, $client_params, $allow_external, $injected_routes); } return $request; }
<?php #---Define-- mb_internal_encoding("UTF-8"); define('ROOT', dirname(__FILE__) . '/../'); #Default Page define('default_page', 'main'); #Admin_login define('admin_login', '*****@*****.**'); #Автозагрузчики include ROOT . 'classes/_autoload.php'; include ROOT . 'models/_autoload.php'; include ROOT . 'controllers/_autoload.php'; #Подключение библиотеки SQL SQL::connect(include ROOT . 'config/db.php'); #User Init User::LoginByCookie(Request::cookie('userid', '')); #QueryStringload Request::Load(); #WebSite Init $controller = mb_strtolower(Request::GetPart(0, default_page)); $action = Request::GetPart(1, 'index'); //if (!User::isLogged()) $controller = 'login'; #Загрузка шаблонизатора Site::$home = 'http://localhost/promspace/'; Site::$template = 'main'; Site::$title = 'PromSpace - Вся промышленность России'; Site::$keywords = 'Вся промышленность России, Предприятия России, Компании России'; Site::Show($controller, $action);
public function testCookie() { $_COOKIE["test"] = 44; $this->assertEquals(44, Request::cookie('test')); $this->assertEquals(null, Request::cookie('not_existing_key')); }
/** * Creates a new request object for the given URI. New requests should be * created using the [Request::instance] or [Request::factory] methods. * * $request = Request::factory($uri); * * If $cache parameter is set, the response for the request will attempt to * be retrieved from the cache. * * @param string $uri URI of the request * @param Cache $cache * @param array $injected_routes an array of routes to use, for testing * @return void|Request * @throws Request_Exception * @uses Route::all * @uses Route::matches */ public static function factory($uri = TRUE, HTTP_Cache $cache = NULL, $injected_routes = array()) { // If this is the initial request if (!Request::$initial) { if (Kohana::$is_cli) { // Default protocol for command line is cli:// $protocol = 'cli'; // Get the command line options $options = CLI::options('uri', 'method', 'get', 'post', 'referrer'); if (isset($options['uri'])) { // Use the specified URI $uri = $options['uri']; } elseif ($uri === TRUE) { $uri = ''; } if (isset($options['method'])) { // Use the specified method $method = strtoupper($options['method']); } else { // Default to GET requests $method = HTTP_Request::GET; } if (isset($options['get'])) { // Overload the global GET data parse_str($options['get'], $_GET); } if (isset($options['post'])) { // Overload the global POST data parse_str($options['post'], $_POST); } if (isset($options['referrer'])) { $referrer = $options['referrer']; } } else { if (isset($_SERVER['SERVER_PROTOCOL'])) { $protocol = $_SERVER['SERVER_PROTOCOL']; } else { $protocol = HTTP::$protocol; } if (isset($_SERVER['REQUEST_METHOD'])) { // Use the server request method $method = $_SERVER['REQUEST_METHOD']; } else { // Default to GET requests $method = HTTP_Request::GET; } if (!empty($_SERVER['HTTPS']) and filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN)) { // This request is secure $secure = TRUE; } if (isset($_SERVER['HTTP_REFERER'])) { // There is a referrer for this request $referrer = $_SERVER['HTTP_REFERER']; } if (isset($_SERVER['HTTP_USER_AGENT'])) { // Browser type Request::$user_agent = $_SERVER['HTTP_USER_AGENT']; } if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) { // Typically used to denote AJAX requests $requested_with = $_SERVER['HTTP_X_REQUESTED_WITH']; } if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) and isset($_SERVER['REMOTE_ADDR']) and in_array($_SERVER['REMOTE_ADDR'], Request::$trusted_proxies)) { // Use the forwarded IP address, typically set when the // client is using a proxy server. // Format: "X-Forwarded-For: client1, proxy1, proxy2" $client_ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); Request::$client_ip = array_shift($client_ips); unset($client_ips); } elseif (isset($_SERVER['HTTP_CLIENT_IP']) and isset($_SERVER['REMOTE_ADDR']) and in_array($_SERVER['REMOTE_ADDR'], Request::$trusted_proxies)) { // Use the forwarded IP address, typically set when the // client is using a proxy server. $client_ips = explode(',', $_SERVER['HTTP_CLIENT_IP']); Request::$client_ip = array_shift($client_ips); unset($client_ips); } elseif (isset($_SERVER['REMOTE_ADDR'])) { // The remote IP address Request::$client_ip = $_SERVER['REMOTE_ADDR']; } if ($method !== HTTP_Request::GET) { // Ensure the raw body is saved for future use $body = file_get_contents('php://input'); } if ($uri === TRUE) { // Attempt to guess the proper URI $uri = Request::detect_uri(); } $cookies = array(); if ($cookie_keys = array_keys($_COOKIE)) { foreach ($cookie_keys as $key) { $cookies[$key] = Cookie::get($key); } } } // Create the instance singleton Request::$initial = $request = new Request($uri, $cache, $injected_routes); // Store global GET and POST data in the initial request only $request->protocol($protocol)->query($_GET)->post($_POST); if (isset($secure)) { // Set the request security $request->secure($secure); } if (isset($method)) { // Set the request method $request->method($method); } if (isset($referrer)) { // Set the referrer $request->referrer($referrer); } if (isset($requested_with)) { // Apply the requested with variable $request->requested_with($requested_with); } if (isset($body)) { // Set the request body (probably a PUT type) $request->body($body); } if (isset($cookies)) { $request->cookie($cookies); } } else { $request = new Request($uri, $cache, $injected_routes); } return $request; }
/** * Cookie相关操作 * @param string $name * @param string $value * @param string $opt * @return string|null */ public static function cookie($name = '', $value = '', $opt = null) { //参数设置处理 if (!is_null($opt)) { if (is_numeric($opt)) { $opt = array('expire' => $opt); //设置有效期 } self::$_cookieConfig = array_merge(self::$_cookieConfig, $opt); } //清除所有Cookie if (is_null($name)) { $cookies = Request::cookies(); if (!empty($cookies)) { foreach ($cookies as $key => $val) { setcookie($key, '', time() - 3600, self::$_cookieConfig['path'], self::$_cookieConfig['domain'], self::$_cookieConfig['secure'], self::$_cookieConfig['httponly']); Request::unsetParam($key, 'cookie'); } } return null; } elseif ('' === $name) { return Request::cookies(); //获取所有cookie } $cookieKey = self::$_cookieConfig['prefix'] . $name; if ('' === $value) { //获取指定的Cookie if (Request::cookie($cookieKey)) { return Request::cookie($cookieKey); } return null; } else { if (is_null($value)) { //删除指定Cookie setcookie($cookieKey, '', time() - 3600, self::$_cookieConfig['path'], self::$_cookieConfig['domain'], self::$_cookieConfig['secure'], self::$_cookieConfig['httponly']); Request::unsetParam($cookieKey, 'cookie'); } else { //设置Cookie $expire = !empty(self::$_cookieConfig['expire']) ? time() + intval(self::$_cookieConfig['expire']) : 0; setcookie($cookieKey, $value, $expire, self::$_cookieConfig['path'], self::$_cookieConfig['domain'], self::$_cookieConfig['secure'], self::$_cookieConfig['httponly']); } } return null; }
/** * Execute the request using PHP stream. (not recommended) * * @param Request $request Request to execute * @return Response */ protected function _native_execute(Request $request) { // Reset the headers Request_Client_External::$_processed_headers = array(); // Calculate stream mode $mode = $request->method() === HTTP_Request::GET ? 'r' : 'r+'; // Process cookies if ($cookies = $request->cookie()) { $request->headers('cookie', http_build_query($cookies, NULL, '; ')); } // Create the context $options = array($request->protocol() => array('method' => $request->method(), 'header' => (string) $request->headers(), 'content' => $request->body(), 'user-agent' => 'Kohana Framework ' . Kohana::VERSION . ' (' . Kohana::CODENAME . ')')); // Create the context stream $context = stream_context_create($options); stream_context_set_option($context, $this->_options); $stream = fopen($request->uri(), $mode, FALSE, $context); $meta_data = stream_get_meta_data($stream); // Get the HTTP response code $http_response = array_shift($meta_data['wrapper_data']); if (preg_match_all('/(\\w+\\/\\d\\.\\d) (\\d{3})/', $http_response, $matches) !== FALSE) { $protocol = $matches[1][0]; $status = (int) $matches[2][0]; } else { $protocol = NULL; $status = NULL; } // Process headers array_map(array('Request_Client_External', '_parse_headers'), array(), $meta_data['wrapper_data']); // Create a response $response = $request->create_response(); $response->status($status)->protocol($protocol)->headers(Request_Client_External::$_processed_headers)->body(stream_get_contents($stream)); // Close the stream after use fclose($stream); return $response; }