Simple php function to check if post variables are set without triggering warnings

If you check the contents of a post variable that never got passed, you get warnings. If you like keeping your verbosity set that high and want to avoid this warning, or you just want to avoid checking against a non-existent variable, try this:

<?php
/**
 * Check to see if a POST variable is set and see if it's empty.
 * Return false if not set, null, empty, etc.
 */
function ispostset($post_var)
{
	if (isset($_POST[$post_var]))
	{
		if ($_POST[$post_var] != '')
		{
			return true;
		}
		else
			return false;
	}
	else
		return false;
}
?>

Now you can collect post variables like this in your code:

if (ispostset("some_post_var"))
	$my_var = $_POST['some_post_var'];
Posted by admica   @   13 August 2009

Related Posts

0 Comments

No comments yet. Be the first to leave a comment !
Leave a Comment

Name

Email

Website

Previous Post
« Send gzipped PHP output to users browser’s to save bandwidth
Next Post
Instakill SSH sessions to mess with ssh-happy users on your box »
Powered by Wordpress   |   Lunated designed by ZenVerse