Few basic Qs about $_SESSION var

sessionnoob. Will someone explain why the session var is assigned in reverse order,
$_SESSION[‘name’] = $myVar;
and not,
$myVar = $_SESSION[‘name’];

And number two, my host has magic quotes turned on, so I have a little scriptie scrubbing all my php vars (post, get, cookie, etc.). When I added the session var, for example,
$_SESSION = array_map(‘trim’, $_SESSION);
to the list, PHP generated an error saying session is not an array, or some such malarky. Now that I look at it, I don’t need to do mysql-real-escape-string or strip-slashes to the session var since its not user input, but why would php say its not an array? or is this just an erroneous error report?
C

Really?
I don’t have to define the array index for post, get, cookie, request. This code runs on everything in that var. Why is session so special?

And number two, my host has magic quotes turned on, so I have a little scriptie scrubbing all my php vars

Magic quotes related directives are ini-per-directory, have you tried overriding your hosts magic quotes settings ?

Create a file in your directory named “php.ini” and place these two lines in it.

magic_quotes_gpc = Off
magic_quotes_runtime = Off

If you’re on Godaddy hosting you will need to name that file “php5.ini” if you’re using PHP 5.

you have to define the session array index

magic_quotes_gpc This feature has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.

The session is not brought into life unless you call session_start. What that does is look for a cookie from the browser (and if not found, sends one), and loads a text file tied to the session id. TBH I forget exactly what happens as that logic is tucked away in my fw, but you can easily find out by var_dump ing $_SESSION before and after calling session_start.

$_SESSION[‘name’] = $myVar;

loads the value from $myVar into the session so it can be passed to subsequent pages

$myVar = $_SESSION[‘name’];

copies the value back from the session into a variable (something rather pointless since you can just as easily reference it within the session)