note 9153 deleted from function.session-register by jimw
| From: | jimw@php.net | Date: | Tue, 18 Dec 2001 22:22:17 +0000 |
| Subject: | note 9153 deleted from function.session-register by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-23253@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.