|
Class cls_request{
private $getdata;//store data for Get
private $postdata;//Store post data
private $requestdata;//store data for request
private $filedata;//Store file data
private $cookiedata;//Storage Cooki
Static $_instance;//instances of this class
Private Function __construct () {
$this->getdata = Self::format_data ($_get);
$this->postdata = Self::format_data ($_post);
$this->requestdata = Array_merge ($this->getdata, $this->postdata);
$this->cookiedata = Self::format_data ($_cookie);
$this->filedata = Self::format_data ($_files);
}
Initializes the class, returning the Cls_request object
public static function Get_instance () {
if (! ( Self::$_instance instanceof Self)) {
Self::$_instance = new self ();
}
return self::$_instance;
}
Gets the numeric variable passed over by get
Public Function Get_num ($key) {
if (!isset ($this->getdata[$key])) {
return false;
}
return $this->to_num ($this->getdata[$key]);
}
Gets the data variable that the post passed over
Public Function Post_num ($key) {
if (!isset ($this->postdata[$key])) {
return false;
}
return $this->to_num ($this->postdata[$key]);
}
Gets the value variable passed by the request.
Public Function Request_num ($key) {
if (!isset ($this->requestdata[$key])) {
return false;
}
return $this->to_num ($this->requestdata[$key]);
}
Get the numeric variables that the cookie passes over
Public Function Cookie_num ($key) {
if (!isset ($this->cookiedata[$key])) {
return false;
}
return $this->to_num ($this->cookiedata[$key]);
}
Gets the numeric variable passed by the file.
Public Function Filedata ($key) {
return $this->filedata[$key];//returns an array
}
Gets the string variable passed over by get
Public Function get_string ($key, $isfilter =true) {
if (!isset ($this->getdata[$key])) {
return false;
}
if ($isfilter) {
return $this->filter_string ($this->getdata[$key]);
}else{
return $this->getdata[$key];
}
}
Gets the string variable that the post passed over
Public Function post_string ($key, $isfilter =true) {
if (!isset ($this->postdata[$key])) {
return false;
}
if ($isfilter) {
return $this->filter_string ($this->postdata[$key]);
}else{
return $this->postdata[$key];
}
}
Gets the string variable that the request passed over
Public Function request_string ($key, $isfilter =true) {
if (!isset ($this->requestdata[$key])) {
return false;
}
if ($isfilter) {
return $this->filter_string ($this->requestdata[$key]);
}else{
return $this->requestdata[$key];
}
}
Gets the string variable passed by the cookie.
Public Function cookie_string ($key, $isfilter =true) {
if (!isset ($this->cookiedata[$key])) {
return false;
}
if ($isfilter) {
return $this->filter_string ($this->cookiedata[$key]);
}else{
return $this->cookiedata[$key];
}
}
Formatting data
Private Function Format_data ($data) {
$result = Array ();
if (!is_array ($data)) {
$data = Array ();
}
/*
*list () indicates that the variable is assigned a value using the value of the array. Arrays that are used only for numeric indexes,
* Starting from 0 bits by default, go in order
*each ()
*/
while (list ($key, $value) = each ($data)) {//Not quite understand
Working with data such as a checkbox
if (Is_array ($value)) {
$result [$key]= $value;
}else{//General Data
$result [$key] = Trim ($value);
Remove whitespace and other predefined characters at both ends of a string
}
}
}
Conversion numbers
Private Function To_num ($num) {
if (Is_numeric ($num)) {
Return Intval ($num);//convert variable to Integer
}else{
return false;
}
}
Swap filter string
Private Function filter_string ($data) {
if ($data ===null) {
return false;
}
if (Is_array ($data)) {
foreach ($data as $k = = $v) {
$data [$k] = Htmlspecialchars ($v, ent_quotes);
Convert some pre-defined characters into HTML entities
}
return $data;
}else{//Ordinary String
Return Htmlspecialchars ($data, ent_quotes);
}
}
}
?>
|