Re: Simple question: $_POST

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 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


-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux