您好,登錄后才能下訂單哦!
/**
* @desc:獲取前端提交的數(shù)據(jù),支持?jǐn)?shù)據(jù)過濾
* @author [Lee] <[<complet@163.com>]>
*/
class getrequest{
/*
@desc:內(nèi)部函數(shù):過濾危險(xiǎn)數(shù)據(jù)
*/
private function safetydata($data){
foreach($data as $k=>$v){
if(is_array($v)){
$data[$k] = $this->safetydata($v);
}else{
$tmp = trim($v);
$tmp = addslashes($tmp);
$data[$k] = $tmp;
}
}
return $data;
}
/*
@desc:判斷前端傳入方式,轉(zhuǎn)換成能用數(shù)據(jù)
*/
public function getrequestdata(){
$data;
$ret;
$contenttype = strtolower($_SERVER['CONTENT_TYPE']);
$method = strtolower($_SERVER['REQUEST_METHOD']);
if($contenttype == 'application/json'){
$data = file_get_contents('php://input');
$data = json_decode($data,true);
}elseif(in_array($contenttype,array('application/x-www-form-urlencoded','multipart/form-data')) || $method == 'post'){
$data = $_POST;
}elseif(in_array($contenttype,array('application/x-www-form-urlencoded','multipart/form-data')) || $method == 'get'){
$data = $_GET;
}else{
parse_str(file_get_contents('php://input'),$data);
}
$ret = $this->safetydata($data);
return $ret;
}
}
$getrequest = new getrequest();
$data = $getrequest->getrequestdata();
var_dump($data);
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。