Re: session_register vs. $_SESSION superglobal
| From: | Justin Patrin | Date: | Tue, 23 Mar 2004 18:05:21 +0000 |
| Subject: | Re: session_register vs. $_SESSION superglobal | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-181291@lists.php.net to get a copy of this message | ||
Kim L. Laage wrote:
(This msg. may arrive twice, with two different senders, I've had a little trouble with the news server) Hi, thanks for your reply.This is due to using this syntax: $_SESSION[user] You want to do this instead: $_SESSION['user'] = $_POST['user']; Whenever you index into an associative array, you should use strings for the key/index (i.e. use quotation marks). That is, unless you're using define(), but that's out of scope for this thread. ;-) -- paperCrane <Justin Patrin>first $_SESSION works like this: session_start(); $_session[user]=$_POST[user];//if using register_globals=off $_SESSION[user]=$user;//if register_globals=on..unsafe though $_SESSION superglobal is an array (usually associative) meaning that the element of the array (the part in the []) is either a variable name orsomecustom name instead of the element number.... $_POST[user] and $user are 2 different variables ifregister_globals=off... Just a couple of questions. 1. I tried adding the lines as you wrote them, but then I got a "Notice: Use of undefined constant user - assumed 'user' in [FILENAME]", I assume I need to add quotation marks around "user" on both sides of the equal sign, that at least removes that notice. 2. I also get a "Notice: Undefined index: user in [FILENAME]", do I need to declare the $_SESSION variable before populating it?