Source for file Request.php
Documentation is available at Request.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Stephan Schmidt <schst@php-tools.net> |
// +----------------------------------------------------------------------+
// $Id: Request.php 176200 2005-01-01 11:28:29Z schst $
* Interface that parses the request
* @author Stephan Schmidt <schst@php-tools.de>
* the data (like POST) sent after the headers
* @param string $request raw request data
* @return array $request parsed request
function &parse($request)
$lines = explode ("\r\n", $request);
// check for method, uri and protocol in line 1
if (!preg_match("'([^ ]+) ([^ ]+) (HTTP/[^ ]+)'", $lines[0 ], $regs)) {
$request->method = $regs[1 ];
$request->uri = $regs[2 ];
$request->protocol = $regs[3 ];
$request->path_info = $tmp['path_info'];
$request->query_string = $tmp['query_string'];
// parse and store additional headers (not needed, but nice to have)
* HTTP1.1 allows headers be broken on several lines if the next line begins with
* a space or a tab (rfc2616#2.2)
for ($i = 1; $i < count($lines); $i++ ) {
if (trim($lines[$i]) == '') {
//empty line, after this the content should follow
if (preg_match("'([^: ]+): (.+)'", $lines[$i], $regs)) {
$request->headers [(strtolower($regs[1 ]))] = $regs[2 ];
//aggregate the content (POST data or so)
for ($i = $i; $i < count($lines); $i++ ) {
$request->content .= $lines[$i] . "\r\n";
* @param string $path uri to parse
* @return array $path path data
if (!preg_match("'([^?]*)(?:\?([^#]*))?(?:#.*)? *'", $path, $regs)) {
'query_string' => isset ($regs[2 ]) ? $regs[2 ] : null
* Exports server variables based on request data
* like _GET, _SERVER[HTTP_*] and so
* The function can be used to make your own
* HTTP server act more than a "real" one (like apache)
//_SERVER[HTTP_*] from headers
foreach ($this->headers as $strId => $strValue) {
$_SERVER['HTTP_HOST'] = substr( $this->headers['host'], 0 , $nPos);
$_SERVER['SERVER_PORT'] = substr( $this->headers['host'], $nPos);
$_SERVER['SERVER_PORT'] = 80;
$_SERVER['SERVER_PROTOCOL'] = $this->protocol;
$_SERVER['REQUEST_METHOD'] = $this->method;
$_SERVER['REQUEST_URI'] = $this->uri;
$_SERVER['argv'] = array ();
//@todo: POST, COOKIE, FILES, SESSION,....
Documentation generated on Mon, 11 Mar 2019 15:39:25 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|