/** * Returns whether generated URLs should be formatted using PATH_INFO, taking the * [usePathInfo](http://craftcms.com/docs/config-settings#usePathInfo) config setting value into account. * * This method will usually only be called in the event that {@link omitScriptNameInUrls()} returns `false` * (so “index.php” _should_ be included), and it determines what follows “index.php” in the URL. * * If it returns `true`, a forward slash will be used, making “index.php” look like just another segment of the URL * (e.g. http://example.com/index.php/some/path). Otherwise the Craft path will be included in the URL as a query * string param named ‘p’ (e.g. http://example.com/index.php?p=some/path). * * If the usePathInfo config setting is set to `true` or `false`, then its value will be returned directly. * Otherwise, `usePathInfo()` will try to determine whether the server is set up to support PATH_INFO. * (See http://craftcms.com/help/enable-path-info for instructions.) * * It does that by creating a dummy request to the site URL with the URI “/index.php/testPathInfo”. If the server * supports it, that request should be sent to Craft’s index.php file, which will detect that this is an * PATH_INFO-testing request, and simply return “success”. If anything besides “success” is returned * (i.e. an Apache-styled 404 error), then Craft assumes the server is not set up to support PATH_INFO. * * Results of the PATH_INFO test request will be cached for the amount of time specified by the * [cacheDuration](http://craftcms.com/docs/config-settings#cacheDuration) config setting. * * @return bool Whether generaletd URLs should be formatted using PATH_INFO. */ public function usePathInfo() { if (!isset($this->_usePathInfo)) { $this->_usePathInfo = 'n'; // Check if the config value has actually been set to true/false $configVal = $this->get('usePathInfo'); if (is_bool($configVal)) { $this->_usePathInfo = $configVal === true ? 'y' : 'n'; } else { // Check if it's cached $cachedVal = craft()->cache->get('usePathInfo'); if ($cachedVal !== false) { $this->_usePathInfo = $cachedVal; } else { // If there is already a PATH_INFO var available, we know it supports it. // Added the !empty() check for nginx. if (!empty($_SERVER['PATH_INFO'])) { $this->_usePathInfo = 'y'; } else { if (AppHelper::isPhpDevServer()) { $this->_usePathInfo = 'y'; } else { // Cache it early so the testPathInfo request isn't checking for it too craft()->cache->set('usePathInfo', 'n'); // Test the server for it try { $url = craft()->request->getHostInfo() . craft()->request->getScriptUrl() . '/testPathInfo'; $client = new \Guzzle\Http\Client(); $response = $client->get($url, array(), array('connect_timeout' => 2, 'timeout' => 4))->send(); if ($response->isSuccessful() && $response->getBody(true) === 'success') { $this->_usePathInfo = 'y'; } } catch (\Exception $e) { Craft::log('Unable to determine if PATH_INFO is enabled on the server: ' . $e->getMessage(), LogLevel::Error); } } } // Cache it craft()->cache->set('usePathInfo', $this->_usePathInfo); } } } return $this->_usePathInfo == 'y'; }
/** * Returns whether generated URLs should be formatted using PATH_INFO. * * @return bool */ public function usePathInfo() { if (!isset($this->_usePathInfo)) { $this->_usePathInfo = 'no'; // Check if the config value has actually been set to true/false $configVal = $this->get('usePathInfo'); if (is_bool($configVal)) { $this->_usePathInfo = $configVal == true ? 'yes' : 'no'; } else { // Check if it's cached $cachedVal = craft()->fileCache->get('usePathInfo'); if ($cachedVal !== false) { $this->_usePathInfo = $cachedVal; } else { // If there is already a PATH_INFO var available, we know it supports it. // Added the !empty() check for nginx. if (!empty($_SERVER['PATH_INFO'])) { $this->_usePathInfo = true; } else { if (AppHelper::isPhpDevServer()) { $this->_usePathInfo = true; } else { // Test the server for it try { $url = craft()->request->getHostInfo() . craft()->request->getScriptUrl() . '/testPathInfo'; $response = \Requests::get($url); if ($response->success && $response->body === 'success') { $this->_usePathInfo = 'yes'; } } catch (\Exception $e) { Craft::log('Unable to determine if PATH_INFO is enabled on the server: ' . $e->getMessage(), LogLevel::Error); } } } // Cache it craft()->fileCache->set('usePathInfo', $this->_usePathInfo); } } } return $this->_usePathInfo == 'no' ? false : true; }