From 9cfd66287e31c0bee3b6b27a5ee79509b907c2eb Mon Sep 17 00:00:00 2001 From: Stefan de Konink Date: Sun, 21 Feb 2010 06:24:01 +0100 Subject: [PATCH] Michael initial webserver in PHP filled the variables also in PHP. This code could therefore be changed into something to provide compatibility between 'global variables' and the new webserver without reinventing the wheel in C. (While some people might not need it at all.) --- examples/fill_server_variables.php | 71 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 examples/fill_server_variables.php diff --git a/examples/fill_server_variables.php b/examples/fill_server_variables.php new file mode 100644 index 0000000..c3be5cf --- /dev/null +++ b/examples/fill_server_variables.php @@ -0,0 +1,71 @@ + time()-$keepAliveTimeout) && ($input = fgets($conn) ) != "\r\n" ) { + while( !feof($conn) && ($input = fgets($conn) ) != "\r\n" ) { + if( preg_match('/([^:]+): (.*)/', $input, $matches) ) { + $HTTP_HEADERS[ strtolower($matches[1]) ] = trim($matches[2]); + } + } + + if( count($HTTP_HEADERS) ) { + $_SERVER['REQUEST_METHOD'] = strtoupper( $inputParsed[0] ); + $_SERVER['REQUEST_URI'] = $inputParsed[1]; + $_SERVER['SERVER_PROTOCOL'] = strtoupper( $inputParsed[2] ); + + $remoteIp = explode( ':', stream_socket_get_name( $conn, true ) ); + $_SERVER['REMOTE_ADDR'] = $remoteIp[0]; + $_SERVER['REMOTE_PORT'] = $remoteIp[1]; + + $_SERVER['HTTP_HOST'] = $HTTP_HEADERS['host']; + $_SERVER['HTTP_USER_AGENT'] = $HTTP_HEADERS['user-agent']; + $_SERVER['HTTP_ACCEPT'] = $HTTP_HEADERS['accept']; + $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $HTTP_HEADERS['accept-language']; + $_SERVER['HTTP_ACCEPT_ENCODING'] = $HTTP_HEADERS['accept-encoding']; + $_SERVER['HTTP_ACCEPT_CHARSET'] = $HTTP_HEADERS['accept-charset']; + $_SERVER['HTTP_KEEP_ALIVE'] = $HTTP_HEADERS['keep-alive']; + $_SERVER['HTTP_CONNECTION'] = $HTTP_HEADERS['connection']; + $_SERVER['HTTP_COOKIE'] = $HTTP_HEADERS['cookie']; + + $_SERVER['SERVER_SOFTWARE'] = '/^_^\istral Enterprise PHP v1.00'; + + $parsed_uri = parse_url($_SERVER['REQUEST_URI']); + parse_str($parsed_uri['query'], $_GET); + + $_SERVER['argv'] = array(0 => $parsed_uri['query']); + $_SERVER['argc'] = count($_SERVER['argv']); + $_SERVER['GATEWAY_INTERFACE'] = 'CGI/1.1'; + $_SERVER['SCRIPT_NAME'] = $parsed_uri['path']; + $_SERVER['PHP_SELF'] = $_SERVER['SCRIPT_NAME']; + $_SERVER['QUERY_STRING'] = $parsed_uri['query']; + + //print_r($_SERVER); + //print_r($_GET); + //print_r($parsed_uri); + + // Determine supported compression method + $gzip = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'); + $deflate = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate'); + $encoding = $gzip ? 'gzip' : ($deflate ? 'deflate' : 'none'); + + // Check for buggy versions of Internet Explorer + if (!strstr($_SERVER['HTTP_USER_AGENT'], 'Opera') && + preg_match('/^Mozilla\/4\.0 \(compatible; MSIE ([0-9]\.[0-9])/i', $_SERVER['HTTP_USER_AGENT'], $matches)) { + $version = floatval($matches[1]); + + if ($version < 6) + $encoding = 'none'; + + if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) + $encoding = 'none'; + } + } +?> -- 2.11.4.GIT