I made some corrections or advances? Hmm... really I don't know what to call it. I have been .NET'ing for a couple of days so I changed it so it assigns the value of the global based on if its get or post with the ability to get the type it is. If your asking for the type it will return and array. index 0 is the value and index 1 is the type. If its neither or its empty the return value is null.
PHP Code:
function request($val,$rtntyp = false)
{
$rtnVal;
if(isset($_GET[$val]) && !empty($_GET[$val]))
{
switch($rtntyp)
{
case false:
$rtnVal = $_GET[$val];
break;
case true:
$rtnVal[0] = $_GET[$val];
$rtnVal[1] = "GET";
default:
$rtnVal = $_GET[$val];
break;
}
}
elseif(isset($_POST[$val]) && !empty($_POST[$val]))
{
switch($rtntyp)
{
case false:
$rtnVal = $_POST[$val];
break;
case true:
$rtnVal[0] = $_POST[$val];
$rtnVal[1] = "GET";
default:
$rtnVal = $_POST[$val];
break;
}
}
else
{
$rtnVal = NULL;
}
return $rtnVal;
}
Sample usage
PHP Code:
$uid = request("uid");
if($uid !== null || $uid !== "")
{
echo $uid;
}
else
{
echo "no value set";
}
I like this version better because you just need to see if there is a value for the variable where you can perform sanitation of the data and type checking. I figure most don't care so long as they can perform the needed actions on it but for integrity purposes I did add type capturing in case you want to know what type it is. Inspired by .NET's request. I would have made it a class but I can't think of any additional method or properties to add to it so it wouldn't serve a point to have a class with one method.