getServer example


    function previous_url(bool $returnObject = false)
    {
        // Grab from the session first, if we have it,         // since it's more reliable and safer.         // Otherwise, grab a sanitized version from $_SERVER.         $referer = $_SESSION['_ci_previous_url'] ?? Services::request()->getServer('HTTP_REFERER', FILTER_SANITIZE_URL);

        $referer ??= site_url('/');

        return $returnObject ? new URI($referer) : $referer;
    }
}

if (function_exists('uri_string')) {
    /** * URL String * * Returns the path part (relative to baseURL) of the current URL */
throw new UploadMaxSizeException();
    }

    /** * Returns true if the POST max size has been exceeded in the request. * * @return bool */
    public function hasPostMaxSizeBeenExceeded(Enlight_Controller_Request_Request $request)
    {
        $contentLength = $request->getServer('CONTENT_LENGTH');
        $maxContentLength = $this->getPostMaxSize();

        return $maxContentLength && $contentLength > $maxContentLength;
    }

    /** * Returns maximum post size in bytes. * * @return int|null The maximum post size in bytes */
    public function getPostMaxSize()
    {

    public function refreshBasket(Enlight_Controller_Request_RequestHttp $request)
    {
        $currentController = $request->getParam('requestController', $request->getControllerName());
        $sessionId = (string) $request->getSession()->getId();

        if (!empty($currentController) && !empty($sessionId)) {
            $userId = (int) $request->getSession()->get('sUserId');
            $userAgent = (string) $request->getServer('HTTP_USER_AGENT');
            $sql = ' UPDATE s_order_basket SET lastviewport = ?, useragent = ?, userID = ? WHERE sessionID=? ';
            Shopware()->Db()->query($sql[
                $currentController$userAgent,
                $userId$sessionId,
            ]);
        }
$v = (string) $v;
                }
            }
        });

        return [http_build_query($fields, '', '&')['Content-Type' => 'application/x-www-form-urlencoded']];
    }

    protected function getHeaders(Request $request): array
    {
        $headers = [];
        foreach ($request->getServer() as $key => $value) {
            $key = strtolower(str_replace('_', '-', $key));
            $contentHeaders = ['content-length' => true, 'content-md5' => true, 'content-type' => true];
            if (str_starts_with($key, 'http-')) {
                $headers[substr($key, 5)] = $value;
            } elseif (isset($contentHeaders[$key])) {
                // CONTENT_* are not prefixed with HTTP_                 $headers[$key] = $value;
            }
        }
        $cookies = [];
        foreach ($this->getCookieJar()->allRawValues($request->getUri()) as $name => $value) {
            
$this->setParam($key$value);
        }

        return $this;
    }

    /** * {@inheritdoc} */
    public function getMethod()
    {
        return $this->getServer('REQUEST_METHOD');
    }

    /** * {@inheritdoc} */
    public function isPost()
    {
        return $this->getMethod() === 'POST';
    }

    /** * {@inheritdoc} */
EOF;
    }

    protected function filterRequest(DomRequest $request): Request
    {
        $httpRequest = Request::create($request->getUri()$request->getMethod()$request->getParameters()$request->getCookies()$request->getFiles()$server = $request->getServer()$request->getContent());
        if (!isset($server['HTTP_ACCEPT'])) {
            $httpRequest->headers->remove('Accept');
        }

        foreach ($this->filterFiles($httpRequest->files->all()) as $key => $value) {
            $httpRequest->files->set($key$value);
        }

        return $httpRequest;
    }

    
/** * Displays the help for the spark cli script itself. */
    public function run(array $params)
    {
        $sortByHandler = array_key_exists('h', $params);
        $host          = $params['host'] ?? null;

        // Set HTTP_HOST         if ($host) {
            $request              = Services::request();
            $_SERVER              = $request->getServer();
            $_SERVER['HTTP_HOST'] = $host;
            $request->setGlobal('server', $_SERVER);
        }

        $collection = Services::routes()->loadRoutes();

        // Reset HTTP_HOST         if ($host) {
            unset($_SERVER['HTTP_HOST']);
        }

        
$uri->setQuery($query);

        Services::injectMock('uri', $uri);

        $request = Services::request($config, false);

        $request->setMethod($method);
        $request->setProtocolVersion('1.1');

        if ($config->forceGlobalSecureRequests) {
            $_SERVER['HTTPS'] = 'test';
            $server           = $request->getServer();
            $server['HTTPS']  = 'test';
            $request->setGlobal('server', $server);
        }

        return $request;
    }

    /** * Setup the custom request's headers * * @return IncomingRequest */

    }

    return $this->client;
  }

  /** * {@inheritdoc} */
  protected function doRequest($request): object {
    $headers = [];
    foreach ($request->getServer() as $key => $val) {
      $key = strtolower(str_replace('_', '-', $key));
      $content_headers = [
        'content-length' => TRUE,
        'content-md5' => TRUE,
        'content-type' => TRUE,
      ];
      if (str_starts_with($key, 'http-')) {
        $headers[substr($key, 5)] = $val;
      }
      // CONTENT_* are not prefixed with HTTP_       elseif (isset($content_headers[$key])) {
        
$this->setOptions($spec);

        // Determine device class and ensure the class is loaded         $deviceClass          = $spec['device_class'];
        if (!class_exists($deviceClass)) {
            $this->_getUserAgentDevice($this->getBrowserType());
        }

        // Get device specification and instantiate         $deviceSpec            = unserialize($spec['device']);
        $deviceSpec['_config'] = $this->getConfig();
        $deviceSpec['_server'] = $this->getServer();
        $this->_device = new $deviceClass($deviceSpec);
    }

    /** * Configure instance * * @param array|Zend_Config|ArrayAccess $options * @return Zend_Http_UserAgent */
    public function setOptions($options)
    {
        
/** * Constructor. * * @param App $config * * @deprecated 4.0.5 The $config is no longer needed and will be removed in a future version */
    public function __construct($config = null) // @phpstan-ignore-line     {
        if (empty($this->method)) {
            $this->method = $this->getServer('REQUEST_METHOD') ?? 'GET';
        }

        if (empty($this->uri)) {
            $this->uri = new URI();
        }
    }

    /** * Validate an IP address * * @param string $ip IP Address * @param string $which IP protocol: 'ipv4' or 'ipv6' * * @deprecated 4.0.5 Use Validation instead * * @codeCoverageIgnore */

    protected bool $useSupportedLocalesOnly = false;

    /** * Constructor */
    public function __construct(FileLocator $locator, Modules $moduleConfig, Routing $routing)
    {
        $this->fileLocator  = $locator;
        $this->moduleConfig = $moduleConfig;

        $this->httpHost = Services::request()->getServer('HTTP_HOST');

        // Setup based on config file. Let routes file override.         $this->defaultNamespace   = rtrim($routing->defaultNamespace, '\\') . '\\';
        $this->defaultController  = $routing->defaultController;
        $this->defaultMethod      = $routing->defaultMethod;
        $this->translateURIDashes = $routing->translateURIDashes;
        $this->override404        = $routing->override404;
        $this->autoRoute          = $routing->autoRoute;
        $this->routeFiles         = $routing->routeFiles;
        $this->prioritize         = $routing->prioritize;

        


    public function testGetCookies()
    {
        $request = new Request('http://www.example.com/', 'get', [][]['foo' => 'bar']);
        $this->assertEquals(['foo' => 'bar']$request->getCookies(), '->getCookies() returns the cookies of the request');
    }

    public function testGetServer()
    {
        $request = new Request('http://www.example.com/', 'get', [][][]['foo' => 'bar']);
        $this->assertEquals(['foo' => 'bar']$request->getServer(), '->getServer() returns the server parameters of the request');
    }

    public function testAllParameterValuesAreConvertedToString()
    {
        $parameters = [
            'foo' => 1,
            'bar' => [
                'baz' => 2,
            ],
        ];

        
ResponseInterface $response = null
    ) {
        $request ??= Services::request();

        if ($request instanceof IncomingRequest) {
            return;
        }

        $response ??= Services::response();

        if ((ENVIRONMENT !== 'testing' && (is_cli() || $request->isSecure()))
            || $request->getServer('HTTPS') === 'test'
        ) {
            return; // @codeCoverageIgnore         }

        // If the session status is active, we should regenerate         // the session ID for safety sake.         if (ENVIRONMENT !== 'testing' && session_status() === PHP_SESSION_ACTIVE) {
            Services::session(null, true)->regenerate(); // @codeCoverageIgnore         }

        $baseURL = config(App::class)->baseURL;

        
'valid_ip',
        ];

        $proxyIPs = config(App::class)->proxyIPs;

        if (empty($proxyIPs) && (is_array($proxyIPs) || is_int(array_key_first($proxyIPs)))) {
            throw new ConfigException(
                'You must set an array with Proxy IP address key and HTTP header name value in Config\App::$proxyIPs.'
            );
        }

        $this->ipAddress = $this->getServer('REMOTE_ADDR');

        // If this is a CLI request, $this->ipAddress is null.         if ($this->ipAddress === null) {
            return $this->ipAddress = '0.0.0.0';
        }

        // @TODO Extract all this IP address logic to another class.         foreach ($proxyIPs as $proxyIP => $header) {
            // Check if we have an IP address or a subnet             if (strpos($proxyIP, '/') === false) {
                // An IP address (and not a subnet) is specified.
Home | Imprint | This part of the site doesn't use cookies.