Understanding session variables with input field and register_global

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


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-20-2007
Otto Wyss
 
Posts: n/a
Default 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
Reply With Quote
  #2 (permalink)  
Old 02-20-2007
Németh Zoltán
 
Posts: n/a
Default Re: [PHP] Understanding session variables with input field andregister_global

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
>

Reply With Quote
  #3 (permalink)  
Old 02-20-2007
Brad Fuller
 
Posts: n/a
Default RE: [PHP] Understanding session variables with input field and register_global

> -----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
Reply With Quote
  #4 (permalink)  
Old 02-20-2007
Richard Lynch
 
Posts: n/a
Default Re: [PHP] Understanding session variables with input field andregister_global

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?
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:58 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0