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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to check if session is defined 1

Status
Not open for further replies.

DrumAt5280

Technical User
Sep 8, 2003
194
US
I created a session varable "session.pre_info" and it works great.

But how do I check to see if the session is declared already?

Code:
<cfif IsStruct("session.pre_info")>
   Do this...
      <cfelse>
         or do this...                    
</cfif>

Is that right?
 
If you want to check that the session structure is defined then yes you would use IsStruct("Session"). but if you want to check for the existance of a variable within the scope, then use good old isDefined('Session.pre_info').

hope this helps!

Tony
 
Thanks. So, if i want to check to see if the session is defined i would do this?

Code:
<cfif IsStruct("session")>
   Do this...
      <cfelse>
         or do this...                    
</cfif>
 

When a session is created session variables called cfid and cftoken are created so you could check for their existance using the method i mention above.

Tony
 
if you want to check for the variable session.pre_info

then the most reliable way would be

Code:
<cfif StructKeyExists(session,"pre_info") >
 Yes, it does exist.
<cfelse>
 No, it doesn't exist.
</cfif>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top