Here is what I'm using:
Code: Select all
<?php
/**
* A basic Request class for accessing any
* user request information available to the script.
*/
class Request{
/**
* Set to true is request method is post
*/
protected $is_post = false;
/**
* Request Data Container
*/
protected $data = array();
/**
* Container for path info
*/
protected $path_info = array();
/**
* Recursively remove php-generated autoslashes
*/
public function __construct() {
if (get_magic_quotes_gpc()) {
$this->removeSlashes($_GET);
$this->removeSlashes($_POST);
$this->removeSlashes($_COOKIE);
}
if (!strcasecmp($_SERVER['REQUEST_METHOD'], 'POST')) {
$this->data =& $_POST;
$this->is_post = true;
} else {
$this->data =& $_GET;
}
if (isset($_SERVER['PATH_INFO'])) {
$this->path_info = explode('/', trim($_SERVER['PATH_INFO'], '/'));
}
}
/**
* Recursively remove php-generated autoslashes
*/
protected function removeSlashes(&$var) {
if (is_array($var)) {
foreach ($var as $name => $value) {
if (is_array($value)) {
$this->removeSlashes($value);
} else {
$var[$name] = stripslashes($value);
}
}
} else {
$var = stripslashes($var);
}
}
/**
* Accessor for Request::data
*/
public function get($name) {
return (isset($this->data[$name]) ? $this->data[$name] : null);
}
/**
* Setter for Request::data
*/
public function set($name, $value) {
$this->data[$name] = $value;
}
/**
* Checks for $name in Request::data
*/
public function has($name) {
return isset($this->data[$name]);
}
public function __get($name){
return $this->get($name);
}
public function is_post(){
return $this->is_post;
}
}
?>I have a few problems:
I don't know really all that much about command line
I don't really know all that much about http
I don't really know where to start... I don't really understand why the posted class uses EITHER get or post... why not have methods like getGet() and getPost()?
Any help/resources/advice is appreciated!
EDIT: Oh yea... keep in mind... I have not even touched anything you could consider ajax, but wouldn't ajax be another type of request?