
Untitled
By: a guest on
Apr 24th, 2012 | syntax:
None | size: 0.66 KB | hits: 14 | expires: Never
PHP how to handle _GET/_POST without duplicating the code base
if($_POST)
{
//then work with the post data
}
if($_GET)
{
//then work with the get data
}
function doOperation($var)
{
//then work with the var data
}
if(isset($_POST))
{
doOperation($_POST);
}
if(isset($_GET))
{
doOperation($_GET);
}
function process($params)
{
//then work with the params
}
if(isset($_POST))
{
process($_POST);
}
if(isset($_GET))
{
process($_GET);
}
if($_SERVER["REQUEST_METHOD"] == "POST") {
$_GET = $_POST;
}
if($_POST)
$varToUse = $_POST;
else if($_GET)
$varToUse = $_GET;
else
$varToUse = 'default case';
//> Process with $varToUse;