Link to home
Start Free TrialLog in
Avatar of JohnMac328
JohnMac328Flag for United States of America

asked on

CF - problem with session id

I have a situation where they want a link to display with either an image of a padlock locked or unlocked depending on the login status of the user.  If they click on the link with the locked padlock they are taken to a login screen.  The login takes the username and password and inserts into tablemembership. They login and it displays the link with an unlocked image.  This works with no problems.  In addition they want a link to sign up in case they need to for obvious reasons.  I have made the signup form and it also works fine and after the form submits the same information into tablemembership, I have a link to go to the page with the links.  The problem is the link still shows a locked padlock image meaning that when they enter the page the session variable is not seeing that they have logged in.  How do I get the signup process to display the links like the login process does.

Any help is appreciated.
       processwhensignupdone.txt loginprocess.txt
Avatar of JohnMac328
JohnMac328
Flag of United States of America image

ASKER

Page with the links and the application.cfm

<table width="400" border="0" align="center">
 <th>Investment Concepts</th>
	<cfif val(session.user_id)> 
 <tr>
    <td><a href="http://localhost/PopUp_Login/dl/book3.xls"><img src="unlocked.gif" width="35" height="35">
    <h3>Link to display if they have</h3></a>
    </td></tr>
  <cfelse>
 <tr>
    <td><A HREF="testlogin.html" onClick="return popup(this, 'notes')"><img src="locked.gif" width="35" height="35">
    <h3>Link to login if they have not signed up</h3></A>
    </td></tr>
  </cfif>
</table>

Open in new window

<cfapplication name="MyApp" clientmanagement="Yes"
                    sessionmanagement="Yes"
                    sessiontimeout="#CreateTimeSpan(0,0,0,10)#"
                    applicationtimeout="#CreateTimeSpan(0,0,0,10)#">

<!--- Now define that this user is logged out by default --->
<CFPARAM NAME="session.allowin" DEFAULT="false">

<!--- Now define this user id to zero by default, this will be used later on to access specific information about this user. --->
<CFPARAM NAME="session.user_id" DEFAULT="0">

Open in new window

Avatar of _agx_
I have made the signup form and it also works fine and after the form submits the same information into tablemembership  ... How do I get the signup process to display the links like the login process does.

Are you actually logging them in after they sign up? Dump the value of #session.user_id# on the sign up page, and again on the page that's showing the locked icon.  Is the value 0?
Hi agx - I have to leave but we can pick this up on Monday if you are in.
Sounds good to me. Have a great w/e :)
You too :)


<cfapplication name="MyApp" clientmanagement="Yes"
                    sessionmanagement="Yes"
                    sessiontimeout="#CreateTimeSpan(0,0,0,10)#"
                    applicationtimeout="#CreateTimeSpan(0,0,0,10)#">


Your session and application timeout is only 10 seconds !    That means the session is thrown out with just 10 seconds after they login..

A more typical time for a session timeout is 20 minutes, and perhaps a few hours for an application

  CreateTimeSpan(0,0,20,0)

Yes - that is just for testing purpose to see if the session kicks in after the membership signup
agx - "Are you actually logging them in after they sign up? Dump the value of #session.user_id# on the sign up page, and again on the page that's showing the locked icon.  Is the value 0?"

Yes - both places I have a value of 0 but the data is being entered into the table

> Yes - that is just for testing purpose to see if the session kicks in after the membership signup

I don't understand your response...  you are aware of it?   but that IS the problem (or at least one of them).

You need to change it before you can test.  


I did - no difference
Ok, that be sure to leave them  both (session and application timeouts) at longer durations while you do the rest of the testing.

If the problem is happening when the user is registering, please show the code that saves the info to the database and then creates the session.user_id.   Be sure not to use CFLOCATION after setting the session variable, it may not stick.
I actually started this question with agx.  Thanks for your input though.
Lol, and you got so far...



agx - Are you actually logging them in after they sign up? ... Dump the value of #session.user_id# ...Is the value 0?"
JohnMac328 - Yes - both places I have a value of 0 but the data is being entered into the table


#session.user_id# shouldn't be 0 because your code says a value of 0 means the user *isn't* logged in.  

<!--- if it's NOT 0 --->
<cfif val(session.user_id)>
    unlocked ...
<cfelse>
    locked
</cfif>

Sounds like the code *isn't* properly logging them in after sign up.  ie It isn't updating the session variable with the new user_id.
... agx, maybe you want to see the code (tell him you want to see the code) ..  he'll listen to you..
I'm always happy to help when I'm around. But I'd actually recommend gdemaria's advice over a LOT of others in this zone when I'm not :)
lol. Man my timing stinks today.  My Posts keep crossing ..
Just did not know the protocol for questions. Ok, after I insert the records into the table it sounds like I need to create the session.user_id, what would that syntax be?  Just run it after the insert statement?
I assume user_id is an identity column in sql server right?  For CF8+ just use the "result" attribute to get the new ID value

<cfquery result="newUser" ....>
          INSERT INTO YourTable ( ....) VALUES (.....)
</cfquery>

Then use it to set the value of your session variable.  

<cfset session.user_id = newUser.IDENTITYCOL>
I get this error and yes user_id is an identity column - the query is called Added

Element IDENTITYCOL is undefined in ADDED.  
 
 
The error occurred in C:\Inetpub\wwwroot\CF_Login2\AA_MembershipSignup.cfm: line 82
 
80 :                   VALUES ('#FORM.user_name#','#FORM.user_pass#','#FORM.Email#','#FORM.firstname#','#FORM.lastname#','#FORM.zipCode#','#FORM.FUND#','#FORM.GROW#')
81 :              </cfquery>
82 :             <cfset session.user_id = Added.IDENTITYCOL>
83 :             <cfset formResults="success" />
 
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Great - thanks again as always.
You're welcome :)

Just did not know the protocol for questions.

Btw: It's nice that you asked :) In this case we hadn't gotten very far yet on Friday. So IMO someone else chiming in is totally fine.  Plus, if you have a question you need answered now, go with the expert that's present and available ;-)  If you feel multiple experts helped solve the problem, you can always accept multiple answers.  For more complicated/involved questions you might prefer to stick with one expert (if they're available). But that's all up to you.