As Sessions is a big deal I have decided to make parts to it. In part 1 we are going to see how to detect if a session is undefined and to create it.

First thing you need to know is that sessions uses structures, you can have multiply structures for your website for different things.

We are going to work up a simple login system using sessions. We are calling the structure loggedin. The first step is to see if the session has been created, so we will need some if statements for the session detect:

Quote:
<cfif not isDefined(‘SESSION.loggedin’)>
</cfif>

Next we want to create the session if its not defined, the code above is shown below but with cfset tags:

Quote:
<cfif not isDefined(‘SESSION.loggedin’)>
<cfset SESSION.loggedin = StructNew()>
<cfset SESSION.loggedin.username = test>
</cfif>

Now what we have asked coldfusion to do is create a new structure (StructNew) with ‘SESSION.loggedin’ as the structure name. After this we want to populate the session structure with a value within the ‘username’ session. We have just used test for now but we go onto bringing in database from a database to work with a login script.

Leave a Reply

Your email address will not be published. Required fields are marked *

About Host Media

We have been hosting websites since 2002 and are always moving forward. All articles written under the Host Media author are created by the team who support our customers.

Category

ColdFusion/Railo & MySQL

Tags