imvkmark
9/24/2014 - 7:49 AM

php:getgpc

php:getgpc

<?php
/**
 * 获取变量
 * @param        $k
 * @param string $type
 * @return null
 */
function getgpc($k, $type = 'GP') {
	$type = strtoupper($type);
	switch ($type) {
		case 'G':
			$var = &$_GET;
			break;
		case 'P':
			$var = &$_POST;
			break;
		case 'C':
			$var = &$_COOKIE;
			break;
		default:
			if (isset($_GET[$k])) {
				$var = &$_GET;
			} else {
				$var = &$_POST;
			}
			break;
	}
	return isset($var[$k]) ? $var[$k] : NULL; //注意这里没有设置的时候返回的是NULL.
}