PDA

Click to See Complete Forum and Search --> : Useful variable testing function


visualAd
May 24th, 2004, 04:43 PM
This is a function I use to test for POST variables which have been passed to my scripts.

It can be modified easily to do the same for variable passed by the GET method, cookies and uploaded files.

Its nothing exciting but saves on typing. Feel free to use. :wave:

/* this function tests for the presence of HTTP post variables passed to the current script
it takes a list containing a variable number of arguments pertaining to the variable name
as set in the name attribute of the form input tags

if all variables passed as arguments are set - the function returns true
if any variables are not set the function returns false

this function is very similar to the isset() function - but saves having to write $_POST
for each variable you want to test
*/
function posted () {
$arglist = func_get_args ();

foreach ($arglist as $arg)
if (! isset ($_POST[$arg])) return false;

return true;
}

The Hobo
May 27th, 2004, 10:08 PM
I can see how that can come in handy and I'll probably use it. Thanks for the idea, visualAd.

CORONA BEER
May 29th, 2004, 11:32 PM
cool ,is that how php handles post request?, i need to make my delphi app post machine info to a php script and then the script log info, but i dont know how to do it, any comments would be helpful.