您好,登錄后才能下訂單哦!
/**
* @desc:獲取前端提交的數據,支持數據過濾
* @author [Lee] <[<complet@163.com>]>
*/
class getrequest{
/*
@desc:內部函數:過濾危險數據
*/
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:判斷前端傳入方式,轉換成能用數據
*/
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);
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。