PHP: GetParam
This PHP function returns the values of POST or GET parameters easy and in a secure way. SESSION and SERVER variables can be returned as well.
Some servers returns an error if the accessed variable is not defined. In this case you have to check if the variable is already defined before you access it. This script does this job for you.
Example
$name = GetParam("p_name");
$name = GetParam("g_name", "G", "Kein Name");
Required
PHP 4.0.4 or higher
License
Open Source (GNU GPL)
Sourcecode
<?php
function GetParam($ParamName, $Method = "P", $DefaultValue = "") {
if ($Method == "P") {
if (isset($_POST[$ParamName])) return $_POST[$ParamName]; else return $DefaultValue;
} else if ($Method == "G") {
if (isset($_GET[$ParamName])) return $_GET[$ParamName]; else return $DefaultValue;
} else if ($Method == "S") {
if (isset($_SERVER[$ParamName])) return $_SERVER[$ParamName]; else return $DefaultValue;
} else if ($Method == "Z") {
if (isset($_SESSION[$ParamName])) return $_SESSION[$ParamName]; else return $DefaultValue;
}
}
?>