0

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?

2
  • 5
    Bridget, you keep asking questions about what hould be very basic stuff. I have no problem helping, but maybe you should refer to more basic documentation first. Try the Adobe help docs, or get a copy of the WACK (Web Application Constructin Kit) book 1. Commented Dec 2, 2009 at 1:05
  • O cool. Ill look them up and give them a try. The Adobe LiveDocs looks good, thanks. Commented Dec 2, 2009 at 1:51

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

13 Comments

OK, I put in my values, but I'm not sure what to put instead of 'un', and the browser errors with 'Element UN is undefined in FORM. '. IS the rest of my code correct do you think? <cfquery datasource = "cfgossip" name = "users"> SELECT IDUsers 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.IDUsers /> </cfif> Thanks for helping my by the way - it's really helping me out.
Are you posting a form to the page this code appears upon? If this is on your signin page, you'd replace form.un with whatever you've put in the NAME attribute of your INPUT field for the user name, and likewise for the password. Or am I missing something? Happy to help. By the way, just for some encouragement, it does get easier - personally, what helped me a lot was hitting the LiveDocs (livedocs.adobe.com/coldfusion/8) for virtually every tag I used to see what I could do with it - they often provide sample code there as well.
ok, cool I start using the into LiveDocs - any help is good. Did you learn ColdFusion by just doing what i'm going to? It's really hard, theres all this jargon which i don't understand.lol. I only have this one site i really want to make before christmas - but i don't acuhally think that's going to happen. lol. Yer, I do have my session variable code on the pages i'm working on... on the login i have the create session etc. am I not meant to? I have on my application.cfc this.sessionmanagement = true; - is all the code meant to be there...?? o no...opps.lol
Well, I had a head start, since I've got a bachelors in CS, but it took a lot of work for me to get into thinking for web development, but now I've been doing it a year and a half professionally, and I'm enjoying it! Your application.cfc is only for stuff that's going to be applied across your CF application (like session management). You'd have the code I mentioned on a seperate login page that you'd post an HTML form to (with INPUT elements for UN, PW, etc.).
ok. Well i've never known about any of the seperate pages before - i'll try use the 'LiveDocs' to get a start so i don't bor you with simple questions. Is the code you gave me (from the answer we writing from above) the correct code for my to add to the seperate login page i'm going to make? Then do i add anycode on the application or login page about linking to the seperate login page - or does all the code about linking come from the seperate login page? ... ok, this looks really complicated - but i'll give it a try! you must make alot from making these sort of sites - I bet there isn't ....
|
0

Ok I think you need a basic breakdown of how this should work. Step 1: User goes to a section of your website/app that needs login. You check if the session.userid is set to a valid value. If not goto login screen.

Step 2: Present user with a login form.

<form action="checklogin.cfm"> <input type="text" name="username" value=""> <input type="password" name="pass" value=""> <input type="submit" value="login"> </form>

Step 3: On clicking login the form is submitted to an action page which checks if the credentials supplied match a valid user.

<cfquery datasource = "myDB" name = "getUsers"> SELECT userID FROM USERS WHERE username = <cfqueryparam cfsqltype = "cf_sql_varchar" value = "#form.username#" /> AND password = <cfqueryparam cfsqltype = "cf_sql_varchar" value = "#form.pass#" /> </cfquery>

Step 4: If valid user goto the logged in area else return to login screen

<cfif getUsers.recordCount GT 0> <cfset session.IDUsers = getUsers.userID /> <cflocation url="home page for logged in users"> <cfelse> <cflocation url="return to login form and display invalid login message"> </cfif>

This is a very basic login form but it should get you started.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.