Class cls_request { Private $ getdata; // Store get data Private $ postdata; // Store post data Private $ requestdata; // store the request data Private $ filedata; // stores file data Private $ cookiedata; // store cooki Static $ _ instance; // instance 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 ); } // Class initialization, return the cls_request object Public static function get_instance (){ If (! (Self: $ _ instance instanceof self )){ Self: $ _ instance = new self (); } Return self: $ _ instance; } // Obtain the value variable passed by GET. Public function get_num ($ key ){ If (! Isset ($ this-> getdata [$ key]) { Return false; } Return $ this-> to_num ($ this-> getdata [$ key]); } // Obtain the data variable passed by POST Public function post_num ($ key ){ If (! Isset ($ this-> postdata [$ key]) { Return false; } Return $ this-> to_num ($ this-> postdata [$ key]); } // Obtain 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]); } // Obtain the value variable passed by the Cookie Public function cookie_num ($ key ){ If (! Isset ($ this-> cookiedata [$ key]) { Return false; } Return $ this-> to_num ($ this-> cookiedata [$ key]); } // Obtain the numeric variable passed by File Public function filedata ($ key ){ Return $ this-> filedata [$ key]; // returns an array } // GET the string variable passed 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]; } } // Obtain the string variable passed by POST 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]; } } // Obtain the string variable passed by the Request 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]; } } // Obtain 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]; } } // Format the 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 array value. Used only for numeric index arrays, * Starts from 0 by default and goes down in order * Each () */ While (list ($ key, $ value) = each ($ data) {// not quite clear // Process data such as checkbox If (is_array ($ value )){ $ Result [$ key] = $ value; } Else {// common data $ Result [$ key] = trim ($ value ); // Delete white spaces and other predefined characters at both ends of the string } } } // Convert numbers Private function to_num ($ num ){ If (is_numeric ($ num )){ Return intval ($ num); // Convert the variable to an integer } Else { Return false; } } // Exchange 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 predefined characters into html objects } Return $ data; } Else {// normal string Return htmlspecialchars ($ data, ENT_QUOTES ); } } } ?> |