This is a discussion on Understanding session variables with input field and register_global within the PHP General forums, part of the PHP Programming Forums category; I've an input field in a form <input name="username" type="text" ... and with ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I've an input field in a form
<input name="username" type="text" ... and with register_global I can use this field in PHP as variable $username. Yet if I use a session variable $_SESSION['username'] = 'value' the variable $username gets the same value. On the other side when I enter a value in the input field, the session variable isn't changed. So how can I set the session variable from the input field after it has changed? O. Wyss |
|
|||
|
2007. 02. 20, kedd keltezéssel 17.32-kor Otto Wyss ezt Ã*rta:
> I've an input field in a form > > <input name="username" type="text" ... > > and with register_global I can use this field in PHP as variable > $username. Yet if I use a session variable > > $_SESSION['username'] = 'value' > > the variable $username gets the same value. the manual says ( http://hu.php.net/manual/en/ref.session.php ) "If register_globals is enabled, then the global variables and the $_SESSION entries will automatically reference the same values which were registered in the prior session instance. However, if the variable is registered by $_SESSION then the global variable is available since the next request." that's why it is the same I think you should read the value from $_POST and put it into $_SESSION to change it hope that helps Zoltán Németh > On the other side when I > enter a value in the input field, the session variable isn't changed. So > how can I set the session variable from the input field after it has > changed? > > O. Wyss > |
|
|||
|
> -----Original Message-----
> From: Otto Wyss [mailto:otto.wyss@orpatec.ch] > Sent: Tuesday, February 20, 2007 11:32 AM > To: php-general@lists.php.net > Subject: [php] Understanding session variables with input field and > register_global > > I've an input field in a form > > <input name="username" type="text" ... > > and with register_global I can use this field in PHP as variable > $username. Yet if I use a session variable > > $_SESSION['username'] = 'value' > > the variable $username gets the same value. On the other side when I > enter a value in the input field, the session variable isn't changed. So > how can I set the session variable from the input field after it has > changed? > > O. Wyss > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > I'm not familiar with an ini setting such as register_globals that would give you similar functionality with session variables. IMHO it seems unlikely that anyone would want EVERY form variable saved in the session (Like the value of your "Submit" button :P)... ... but if you REALLY want to do it, you could do something like this: foreach($_POST as $key => $val) { $_SESSION[$key] = $val; } HTH, Brad |
|
|||
|
On Tue, February 20, 2007 10:32 am, Otto Wyss wrote:
> I've an input field in a form > > <input name="username" type="text" ... > > and with register_global I can use this field in PHP as variable > $username. You really really should turn OFF register_global for new code development... > Yet if I use a session variable > > $_SESSION['username'] = 'value' > > the variable $username gets the same value. On the other side when I > enter a value in the input field, the session variable isn't changed. > So > how can I set the session variable from the input field after it has > changed? If you want to sort out the mess of which variables are coming from where, use $_POST and $_SESSION and $_GET instead of $username You should not blindly put POST/GET data into your SESSION data. NEVER trust user-supplied data. Start reading about that here: http://phpsec.org/ > > O. Wyss > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? |