Re: Simple question: $_POST

From: Date: Sat, 15 Jan 2005 09:30:44 +0000
Subject: Re: Simple question: $_POST
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-206428@lists.php.net to get a copy of this message
Jochem Maas wrote:
Stuart Felenstein wrote:
When using $_POST vars is it required that a form is used ? In other words I can create an href link and echo variable and pick them up using $_GET in the following page. No so with $_POST ?
in order to create POST vars the proper request headers need to sent to the browser. that could be done with some newfangled javascript
I had a bit of a thinko there - that should have read '...sent to the server' not '...sent to the browser', sorry!
techniques e.g. XHTTPRequest object - see sitepoint.com (Harry Fuecks article) if you don't care if a var comes via post or get you could use a func like this to avoid having to check both superglobals everytime /** * getGP() * * this function will return the value of a GET or POST var that corresponds to the * variable name pasted, if nothing is found NULL is returned. contents of POST array * takes precendence over the contents of the GET array. You can specify a value as second argument * which will be returned if the GP var *does not* exist; a third parameter can be given to * which will act as the return value if the GP *does* exist - the limitation is that the parameter cannot be * used to return a literal NULL; but I suggest that this would probably be a silly thing to do in practice * * @var string $v // the name of GP variable whose value to return * @var mixed $r // value to return if the GP variable was not set * @var mixed $t // value to return if the GP variable was set (i.e. override the value from GP) * * @return mixed */ function getGP($v = '', $r = null, $t = null) {
    if (!empty($v)) {
        if (isset($_GET[$v]))  { $r = (!is_null($t)) ? $t: $_GET[$v]; }
        if (isset($_POST[$v])) { $r = (!is_null($t)) ? $t: $_POST[$v];}
    }
    return $r;
}
Stuart


« previous php.general (#206428) next »