[SOLVED] $_post OR $_get

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hairyjim
Forum Contributor
Posts: 219
Joined: Wed Nov 13, 2002 9:04 am
Location: Warwickshire, UK

[SOLVED] $_post OR $_get

Post 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
Last edited by hairyjim on Tue Jun 15, 2004 8:03 am, edited 1 time in total.
PAW Projects
Forum Commoner
Posts: 30
Joined: Tue Jun 15, 2004 7:43 am
Contact:

Post 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; }
	}
?>
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

also, the $_REQUEST superglobal array will get them both but is not generally a good idea safety wise so use it carefully
hairyjim
Forum Contributor
Posts: 219
Joined: Wed Nov 13, 2002 9:04 am
Location: Warwickshire, UK

Post by hairyjim »

$_REQUEST I think that was the one I was thinking of.

Will read up on its abilities before using.
Post Reply