Okay, heres what Ive come up with for my own HTTP Request handler library. It handles both & and ; delimeted query-strings and parses 'search-engine friendly' style url'l as well as handling cookies.
Its by no means a finished work, but I was curious as to what you all thought of it. 
Here is the base class, HTTP_Request:
PHP Code:
<?php
class HTTP_Request
{
var $param;
var $raw_query;
var $cookie_vars;
var $query_string;
function HTTP_Request()
{
}
function parse_requests()
{
if( is_array($GLOBALS['_GET']) )
{
while( list($gk,$gv) = each($GLOBALS['_GET']) )
{
if( is_array($gk) )
{
while( list($ngk,$ngv) = each($GLOBALS['_GET'][$gk]) )
{
$this->raw_query[$gk][$ngk] = $ngv;
}
}
else
{
$this->raw_query[$gk] = $gv;
}
}
}
if( is_array($GLOBALS['_POST']) )
{
while( list($pk,$pv) = each($GLOBALS['_POST']) )
{
if( is_array($pk) )
{
while( list($npk,$npv) = each($GLOBALS['_POST'][$pk]) )
{
$this->raw_query[$pk][$npk] = $npv;
}
}
else
{
$this->raw_query[$pk] = $pv;
}
}
}
if(is_array($_COOKIE))
{
while( list($ck,$cv) = each($_COOKIE) )
{
if(is_array($ck))
{
while( list($nck,$ncv) = each($_COOKIE[$ck]) )
{
$this->cookie_vars[$ck][$nck] = $ncv;
}
}
else
{
$this->cookie_vars[$ck] = $cv;
}
}
}
if(isset($_SERVER['QUERY_STRING']))
{
$this->query_string = $_SERVER['QUERY_STRING'];
}
}
function get_Requests()
{
return $this->raw_param;
}
function get_Cookies()
{
return $this->cookie_vars;
}
function set_Cookie($name,$value='', $expire='',$path='',$domain='',$secure='')
{
$expire = $expire == "" ? "" : time()+3600;
return setcookie($name,$value,$expire,$path,$domain,$secure);
}
function param($pval)
{
die('Feature not implemented.');
}
function dump_Params()
{
die('Feature not implemented.');
}
}
?>
The query-string parser class:
PHP Code:
<?php
if(!defined('CLASS_ROOT'))
{
define('CLASS_ROOT', '');
}
include_once CLASS_ROOT."HTTP_Request.php";
class QS_HTTP_Request extends HTTP_Request
{
var $use_ampersands;
function QS_HTTP_Request($use_amp = 'false' )
{
$this->use_ampersands = $use_amp;
$this->parse_requests();
if(is_array($this->raw_query))
{
if( $this->use_ampersands == 'false' )
{
while( list($k,$v) = each($this->raw_query) )
{
$this->param[ $k ] = urldecode($v);
}
}
else
{
$this->parse_params($this->query_string);
}
}
}
function param($pval)
{
return $this->param[$pval];
}
function dump_Params()
{
return $this->param;
}
function parse_params($tosplit)
{
$pairs = preg_split( '/[&;]/', $tosplit );
foreach( $pairs as $vars )
{
list($k,$v) = explode( '=', $vars );
$value = isset($value) ? $value : '';
$param = urldecode($k);
$value = urldecode($v);
$this->param[ $param ] = $value;
}
}
}
?>
And the search-engine friendly url parser class:
PHP Code:
<?php
if(!defined('CLASS_ROOT'))
{
define('CLASS_ROOT', '');
}
include_once CLASS_ROOT."HTTP_Request.php";
class SEF_HTTP_Request extends HTTP_Request
{
var $temp_vars;
function SEF_HTTP_Request()
{
$this->parse_requests();
$this->temp_vars = explode( '/',$_SERVER["PATH_INFO"] );
array_shift($this->temp_vars);
reset($this->temp_vars);
while( list($v,$k) = each($this->temp_vars) )
{
list($index,$val) = each($this->temp_vars);
$val = urldecode($val);
$this->param[$k] = $val;
$$k = $val;
}
}
function param($pval)
{
return $this->param[$pval];
}
function dump_Params()
{
return $this->param;
}
}
?>
Bookmarks