Created
September 28, 2014 05:57
-
-
Save JingwenTian/d4999b6ab2e3f650e26f to your computer and use it in GitHub Desktop.
安全获取 GET/POST 的参数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* 安全获取 GET/POST 的参数 | |
* | |
* @param String $request_name | |
* @param Mixed $default_value | |
* @param String $method 'post', 'get', 'all' default is 'all' | |
* @return String | |
*/ | |
function getRequest($request_name, $default_value = null, $method = "all") | |
{ | |
$magic_quotes = ini_get("magic_quotes_gpc") ? true : false; | |
$method = strtolower($method); | |
switch (strtolower($method)) { | |
default: | |
case "all": | |
if (isset($_POST[$request_name])) { | |
return $magic_quotes ? stripslashes($_POST[$request_name]) : $_POST[$request_name]; | |
} else if (isset($_GET[$request_name])) { | |
return $magic_quotes ? stripslashes($_GET[$request_name]) : $_GET[$request_name]; | |
} else { | |
return $default_value; | |
} | |
break; | |
case "get": | |
if (isset($_GET[$request_name])) { | |
return $magic_quotes ? stripslashes($_GET[$request_name]) : $_GET[$request_name]; | |
} else { | |
return $default_value; | |
} | |
break; | |
case "post": | |
if (isset($_POST[$request_name])) { | |
return $magic_quotes ? stripslashes($_POST[$request_name]) : $_POST[$request_name]; | |
} else { | |
return $default_value; | |
} | |
break; | |
default: | |
return $default_value; | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment