PHP 8.2.30
Preview: ServerBag.php Size: 3.62 KB
//opt/cloudlinux/alt-php55/root/usr/share/pear/Symfony/Component/HttpFoundation/ServerBag.php

<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\HttpFoundation;

/**
 * ServerBag is a container for HTTP headers from the $_SERVER variable.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 * @author Bulat Shakirzyanov <mallluhuct@gmail.com>
 * @author Robert Kiss <kepten@gmail.com>
 */
class ServerBag extends ParameterBag
{
    /**
     * Gets the HTTP headers.
     *
     * @return array
     */
    public function getHeaders()
    {
        $headers = array();
        $contentHeaders = array('CONTENT_LENGTH' => true, 'CONTENT_MD5' => true, 'CONTENT_TYPE' => true);
        foreach ($this->parameters as $key => $value) {
            if (0 === strpos($key, 'HTTP_')) {
                $headers[substr($key, 5)] = $value;
            }
            // CONTENT_* are not prefixed with HTTP_
            elseif (isset($contentHeaders[$key])) {
                $headers[$key] = $value;
            }
        }

        if (isset($this->parameters['PHP_AUTH_USER'])) {
            $headers['PHP_AUTH_USER'] = $this->parameters['PHP_AUTH_USER'];
            $headers['PHP_AUTH_PW'] = isset($this->parameters['PHP_AUTH_PW']) ? $this->parameters['PHP_AUTH_PW'] : '';
        } else {
            /*
             * php-cgi under Apache does not pass HTTP Basic user/pass to PHP by default
             * For this workaround to work, add these lines to your .htaccess file:
             * RewriteCond %{HTTP:Authorization} ^(.+)$
             * RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
             *
             * A sample .htaccess file:
             * RewriteEngine On
             * RewriteCond %{HTTP:Authorization} ^(.+)$
             * RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
             * RewriteCond %{REQUEST_FILENAME} !-f
             * RewriteRule ^(.*)$ app.php [QSA,L]
             */

            $authorizationHeader = null;
            if (isset($this->parameters['HTTP_AUTHORIZATION'])) {
                $authorizationHeader = $this->parameters['HTTP_AUTHORIZATION'];
            } elseif (isset($this->parameters['REDIRECT_HTTP_AUTHORIZATION'])) {
                $authorizationHeader = $this->parameters['REDIRECT_HTTP_AUTHORIZATION'];
            }

            if (null !== $authorizationHeader) {
                if (0 === stripos($authorizationHeader, 'basic')) {
                    // Decode AUTHORIZATION header into PHP_AUTH_USER and PHP_AUTH_PW when authorization header is basic
                    $exploded = explode(':', base64_decode(substr($authorizationHeader, 6)));
                    if (count($exploded) == 2) {
                        list($headers['PHP_AUTH_USER'], $headers['PHP_AUTH_PW']) = $exploded;
                    }
                } elseif (empty($this->parameters['PHP_AUTH_DIGEST']) && (0 === stripos($authorizationHeader, 'digest'))) {
                    // In some circumstances PHP_AUTH_DIGEST needs to be set
                    $headers['PHP_AUTH_DIGEST'] = $authorizationHeader;
                    $this->parameters['PHP_AUTH_DIGEST'] = $authorizationHeader;
                }
            }
        }

        // PHP_AUTH_USER/PHP_AUTH_PW
        if (isset($headers['PHP_AUTH_USER'])) {
            $headers['AUTHORIZATION'] = 'Basic '.base64_encode($headers['PHP_AUTH_USER'].':'.$headers['PHP_AUTH_PW']);
        } elseif (isset($headers['PHP_AUTH_DIGEST'])) {
            $headers['AUTHORIZATION'] = $headers['PHP_AUTH_DIGEST'];
        }

        return $headers;
    }
}

Directory Contents

Dirs: 3 × Files: 21

Name Size Perms Modified Actions
File DIR
- drwxr-xr-x 2024-03-03 22:54:39
Edit Download
Resources DIR
- drwxr-xr-x 2024-03-03 22:54:39
Edit Download
Session DIR
- drwxr-xr-x 2024-03-03 22:54:39
Edit Download
3.53 KB lrw-r--r-- 2019-12-18 11:24:06
Edit Download
4.80 KB lrw-r--r-- 2019-12-18 11:24:06
Edit Download
930 B lrw-r--r-- 2019-12-18 11:24:06
Edit Download
344 B lrw-r--r-- 2019-12-18 11:24:06
Edit Download
9.43 KB lrw-r--r-- 2019-12-18 11:24:06
Edit Download
4.95 KB lrw-r--r-- 2019-12-18 11:24:06
Edit Download
1.33 KB lrw-r--r-- 2019-12-18 11:24:06
Edit Download
3.94 KB lrw-r--r-- 2019-12-18 11:24:06
Edit Download
7.95 KB lrw-r--r-- 2019-12-18 11:24:06
Edit Download
3.43 KB lrw-r--r-- 2019-12-18 11:24:06
Edit Download
4.52 KB lrw-r--r-- 2019-12-18 11:24:06
Edit Download
7.91 KB lrw-r--r-- 2019-12-18 11:24:06
Edit Download
2.63 KB lrw-r--r-- 2019-12-18 11:24:06
Edit Download
54.60 KB lrw-r--r-- 2019-12-18 11:24:06
Edit Download
3.71 KB lrw-r--r-- 2019-12-18 11:24:06
Edit Download
791 B lrw-r--r-- 2019-12-18 11:24:06
Edit Download
2.32 KB lrw-r--r-- 2019-12-18 11:24:06
Edit Download
34.97 KB lrw-r--r-- 2019-12-18 11:24:06
Edit Download
8.64 KB lrw-r--r-- 2019-12-18 11:24:06
Edit Download
3.62 KB lrw-r--r-- 2019-12-18 11:24:06
Edit Download
3.14 KB lrw-r--r-- 2019-12-18 11:24:06
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).