Value for the session variable

coldfusion

Here my code to create a session variable:

<cflock timeout="999" scope="Session" type="Exclusive">
  <cfset Session.IDUsers = "">
</cflock>

I need to put a value in = "" but I want the value to change to be the users ID depending on which user is logged in. So I can't just put any number etc. in there. What do I have to do?

Best Answer

Basically, you're going to do this when you log your user in. A sign-in routine might look like the following:

<cfquery datasource="cfgossip" name="signin">
  SELECT 
    ID_USERS 
  FROM 
    USERS 
  WHERE 
    UN = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.un#" /> 
    AND PW = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.pw#" />
</cfquery>
<cfif signin.recordCount>
  <cfset session.idUsers = signin.id_users />
</cfif>

Until they've logged in, you can't know what the value you need is. However, once you've determined that they are who they say they are and you're going to let them in, you can then set the session variable.

Related Topic