-
Notifications
You must be signed in to change notification settings - Fork 130
/
common.inc.php
58 lines (51 loc) · 1.51 KB
/
common.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
// vim: set et sw=4 ts=4 sts=4 fdm=marker ff=unix fenc=utf8 nobomb:
/**
* 公共函数库
*
* @author mingcheng<i.feelinglucky#gmail.com>
* @date 2011-02-17
* @link http://www.gracecode.com/
*/
/**
* 安全获取 GET/POST 的参数
*
* @param String $request_name
* @param Mixed $default_value
* @param String $method 'post', 'get', 'all' default is 'all'
* @return String
*/
function getRequestParam($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;
}
}