Page 1 of 1

[SOLVED] $_post OR $_get

Posted: Tue Jun 15, 2004 7:47 am
by hairyjim
Hi,

I have a script that I may take input from several forms that could be sending data either by POST or GET methods.

Is there a line of code to help me retrieve the submitted form data regardless of POST or GET being used?

I thought there was somehting but I can't remember what it is and that doesn't help when trying to search for something when you don't know what it is called :wink:

Cheers

Posted: Tue Jun 15, 2004 7:54 am
by PAW Projects
I find that using a little common function like this solves a lot of trouble:

Code: Select all

<?php
	function get_var($n, $default='') {
		if			(isset($_POST[$n]))	{ return $_POST[$n]; }
		elseif	(isset($_GET[$n]))	{ return $_GET[$n]; }
		else												{ return $default; }
	}
?>

Posted: Tue Jun 15, 2004 7:59 am
by magicrobotmonkey
also, the $_REQUEST superglobal array will get them both but is not generally a good idea safety wise so use it carefully

Posted: Tue Jun 15, 2004 8:03 am
by hairyjim
$_REQUEST I think that was the one I was thinking of.

Will read up on its abilities before using.