Click to See Complete Forum and Search --> : session variables vs scope


GrepZen
12-25-2006, 04:19 AM
'Lo All,

I'm learning PHP from an ASP background. I've searched found and read some articles on PHP's variable scope but can't find --or need help finding-- something that addresses the scope of session variables.

That just sounds funny to ask. I'd have thougth that a session variable is a session variable no matter where when or how it's defined.

session_start();

function SomeFunction(){
$_session['SomeVarName'] = 'of Value';
}

//calling the function
SomeFunction();

echo 'there should be something '. $_session['SomeVarName'] .' here.';


So comes the question, how can I assign a session variable and make it available in and out of functions? "global $_session['SomeVarName'];" doesn't seem to be doing the trick.

Any insight you could offer or even links to related articles would be welcomed.

Respectfully,
Micke

pcthug
12-25-2006, 04:46 AM
Try Capitalizing your calls to the session superglobal variable. Like so:
session_start();

function SomeFunction(){
$_SESSION['SomeVarName'] = 'of Value';
}

//calling the function
SomeFunction();

echo 'there should be something '. $_SESSION['SomeVarName'] .' here.';

GrepZen
12-25-2006, 05:04 AM
well that was embarasingly simple!

pcthug, thanks! worked fine!

lotuzwine
12-26-2006, 01:55 PM
lol