Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

$_SESSION variable scopes

Status
Not open for further replies.

BiggerBrother

Technical User
Sep 9, 2003
702
GB
I thought this was an easy thing that I over looked, and after a long week, and now wanting to quit for the weekend, I can't seem to see the wood for the trees!

I have a function, and within the function I refer to a session variable. I've tried echoing out the variable, and I don't get anything, when I know that the session is populated. What am I missing? The function is called by another function, which is in an included file.

Within the function I just have echo "this is the variable" . $_SESSION['variable_name']; , and it only returns the "this is the variable" bit.

Any help would be gratefully received.

Many thanks

BB
 
either the variable is not set ;> or the session has not been started or both.
 
I agree.

$_SESSION is a superglobal array. Superglobal variables are, by definition, available in every variable scope.

So either the element was not set or the entire array was not instantiated.



Want the best answers? Ask the best questions! TANSTAAFL!
 
You could try using: error_reporting(E_ALL), and run the script.

If the session has not been started you will get a
Notice: Undefined variable _SESSION: in...

If the session has been started but the variable within the session array does not exist you will get:
Notice: Undefined index: variable_name in...

This should tell you where the problem lies.
 
Many thanks for your responses. It now works perfectly.

BB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top