Tired of typing if(isset($_POST['submit'] && $_POST['submit'] == 'UPDATE'))? Here is a simple class that will abstract some of that.
By : MadAlbert
<? class req { function get($var,$sub=False){ return (isset($_GET[$var]))? $_GET[$var]:$sub; } function post($var,$sub=False){ return (isset($_POST[$var]))? $_POST[$var]:$sub; } function request($var,$sub=False){ return (isset($_REQUEST[$var]))? $_REQUEST[$var]:$sub; } function server($var,$sub=False){ return (isset($_SERVER[$var]))? $_SERVER[$var]:$sub; } function session($var,$sub=False){ return (isset($_SESSION[$var]))? $_SESSION[$var]:$sub; } function getEQ($var,$eq){ return (req::get($var) == $eq)?True:False; } function postEQ($var,$eq){ return (req::post($var) == $eq)?True:False; } function requestEQ($var,$eq){ return (req::request($var) == $eq)?True:False; } function serverEQ($var,$eq){ return (req::server($var) == $eq)?True:False; } function sessionEQ($var,$eq){ return (req::session($var) == $eq)?True:False; } }
/*USAGE
There is no need to instanciate the class has it has no internal values to track so usage is like this:
if(req::postEQ('submit','UPDATE')){ do something; } if you need to see if a variable is set then use
if(req::post('submit'){ do something; } If you need to use the posted variable but have a replacement if it is not set then do:
$name = req::post('name','no name given'); or $id = req::post('userid',0);
There are macros for _POST _GET _REQUEST _SERVER and _SESSION Doing it this way you just need to include the class, I use auto prepend to do it automatically on every page. */
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.