<?php
class
cls_request{
private
$getdata
;
private
$postdata
;
private
$requestdata
;
private
$filedata
;
private
$cookiedata
;
static
$_instance
;
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
);
}
public
static
function
get_instance(){
if
(!(self::
$_instance
instanceof
self)){
self::
$_instance
=
new
self();
}
return
self::
$_instance
;
}
public
function
get_num(
$key
){
if
(!isset(
$this
->getdata[
$key
])){
return
false;
}
return
$this
->to_num(
$this
->getdata[
$key
]);
}
public
function
post_num(
$key
){
if
(!isset(
$this
->postdata[
$key
])){
return
false;
}
return
$this
->to_num(
$this
->postdata[
$key
]);
}
public
function
request_num(
$key
){
if
(!isset(
$this
->requestdata[
$key
])){
return
false;
}
return
$this
->to_num(
$this
->requestdata[
$key
]);
}
public
function
cookie_num(
$key
){
if
(!isset(
$this
->cookiedata[
$key
])){
return
false;
}
return
$this
->to_num(
$this
->cookiedata[
$key
]);
}
public
function
filedata(
$key
){
return
$this
->filedata[
$key
];
}
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
];
}
}
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
];
}
}
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
];
}
}
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
];
}
}
private
function
format_data(
$data
){
$result
=
array
();
if
(!
is_array
(
$data
)){
$data
=
array
();
}
while
(list(
$key
,
$value
) = each(
$data
)){
if
(
is_array
(
$value
)){
$result
[
$key
]=
$value
;
}
else
{
$result
[
$key
] = trim(
$value
);
}
}
}
private
function
to_num(
$num
){
if
(
is_numeric
(
$num
)){
return
intval
(
$num
);
}
else
{
return
false;
}
}
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);
}
return
$data
;
}
else
{
return
htmlspecialchars(
$data
,ENT_QUOTES);
}
}
}
?>