note 9153 added to session_register
| From: | kgolding at webcom dot com dot au | Date: | Thu, 19 Oct 2000 02:50:58 +0000 |
| Subject: | note 9153 added to session_register | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-6690@lists.php.net to get a copy of this message | ||
Re: GET and POST values overriding session variables.
For those situations where I specifically want GET and POST variables to override values in session
variables, I wrote the following function....
function grabvar($varname)
{
global $$varname, $HTTP_GET_VARS, $HTTP_POST_VARS;
session_register($varname);
if (isset($HTTP_POST_VARS[$varname]))
{
$$varname = $HTTP_POST_VARS[$varname];
}
if (isset($HTTP_GET_VARS[$varname]))
{
$$varname = $HTTP_GET_VARS[$varname];
}
}
?>
I put it into a file which I always include in the head of all my php scripts. Then in the scripts,
instead of session_register(), I call my function, like this...
<?php
require("utils.inc");
grabvar("my_var");
grabvar("my_other_var");
?>
Thus I have a reasonably neat and tidy way of reading GET and POST values into sessions and still
maintaining control over exactly which variables get saved.
http://www.php.net/manual/function.session-register.php