/    Sign up×
Community /Pin to ProfileBookmark

session variables vs scope

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

[code=php]session_start();

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

//calling the function
SomeFunction();

echo ‘there should be something ‘. $_session[‘SomeVarName’] .’ here.’;
[/code]

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

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@pcthugDec 25.2006 — Try Capitalizing your calls to the session superglobal variable. Like so:
[code=php]session_start();

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

//calling the function
SomeFunction();

echo 'there should be something '. $_SESSION['SomeVarName'] .' here.';[/code]
Copy linkTweet thisAlerts:
@GrepZenauthorDec 25.2006 — well that was embarasingly simple!

[B]pcthug[/B], thanks! worked fine!
Copy linkTweet thisAlerts:
@lotuzwineDec 26.2006 — lol
×

Success!

Help @GrepZen spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...