SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to control the user name throughout the system?

    I want to control the user name which is loggin into the application. Once the user is logged in, the username should be saved through out the system until the user logged out. For that matter, how can i keep the user name? Should i use cookie or session? How is the difference and which is better?
    Is anything sample to use these, please let me see.
    Thanks.

  2. #2
    SitePoint Member
    Join Date
    Aug 2005
    Location
    Port Harcourt, Nigeria
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have to use the sesion. This maeks only one user active on the same computer at the same time. Note, you also have to set your session.timeout as not to allow users stay inactive for so long. The session could not be framed by users as cookies could be.
    gfjhjnjkllkm**un*77ubajk;.JBJjnjNKkal,sl,ml,LL>,l,laskmskmls4dkn
    kmksmkmdm,MKMkmkMKSmksjkmkKJIKjkj(78989Ftcv{{]]\MklmO9mK
    M<==)h7&bhbHBU7y7yB^67t7vT&G^&6tGYGygyG&y78Y7&7t^T6t^*80uH

  3. #3
    Guru Bullschmidt's Avatar
    Join Date
    Apr 2002
    Location
    USA
    Posts
    524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perhaps this may hopefully give you some ideas:

    Classic ASP Design Tips - Login Page
    http://www.bullschmidt.com/devtip-loginpage.asp

    Perhaps have a login page that asks the user for his username and password. And whatever page that posts to (which could be the same page for a self posting form) tests these fields against what is in the database, sets the username and userlevel session variables accordingly, and then redirects to the proper page - i.e. back to the login page if the password is wrong (perhaps with a JavaScript popup saying wrong username/password combination) or to the main menu page if the password is correct:

    Session("UserName") = objRS("UserName")
    Session("UserLevel") = objRS("UserLevel")
    Response.Redirect "mainmenu.asp"

    Then you can use If Then's or Select Case on each page to control whether a user is allowed to actually be there and whether particular links of where a user can go actually show up.

    If (Session("UserLevel") <> "Admin") And (Session("UserLevel") <> "Regular") Then
    Response.Redirect "login.asp"
    End If
    J. Paul Schmidt
    www.Bullschmidt.com - Freelance Web and Database Developer
    www.Bullschmidt.com/DevTip.asp - Classic ASP Design Tips

  4. #4
    SitePoint Member
    Join Date
    Aug 2005
    Location
    Port Harcourt, Nigeria
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah! It is not good! This will allow only the admin to login to the page. And this will not protect the pages from users that are not logged in. The code for this is ery long. I got the code fom microsoft but I have forgotten the web address. If yu are interested in getting a script for protecting your website and also allowing other users to register and login too, mail me at <snip /> and I will give you enough of it. It is too long to be listed here.
    Last edited by DaveMaxwell; Apr 23, 2009 at 08:57. Reason: removed email address....
    gfjhjnjkllkm**un*77ubajk;.JBJjnjNKkal,sl,ml,LL>,l,laskmskmls4dkn
    kmksmkmdm,MKMkmkMKSmksjkmkKJIKjkj(78989Ftcv{{]]\MklmO9mK
    M<==)h7&bhbHBU7y7yB^67t7vT&G^&6tGYGygyG&y78Y7&7t^T6t^*80uH

  5. #5
    SitePoint Member
    Join Date
    Aug 2005
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want to keep the username until the user "logs out" then you must use cookie because session keeps information until the user closes his/her browser or enters another web page. On many sites you can see the "Remember Me" checkbox on login pages if the user checks that box then the information goes to cookies and to have the site not to remember him/her the user must click on a "logout" button if the user does not check the "Remember Me" box then the information goes to sessions so that the site remembers the user until user quits from that site and user does not need to click any "log out" link.

    Setting a cookie:

    Code:
    Response.Cookies("Your_Cookies_Name")("Username") = Request.Form("Username")
    Response.Cookies("Your_Cookies_Name").Expires = Now() + 365 'This line sets when to expire the cookie, you know "Everything that has a beginning has an end." :). For example, this cookie will expire after 365 days.
    Setting a session:

    Code:
    Session("Username") = Request.Form("Username")
    After your user login then you can use a system like this to get the information:

    Code:
    Member_No = Session("Username")
    If Member_No = "" Then
    	Member_No = Response.Cookies("Your_Cookies_Name")("Username")
    End If
    
    If Member_No <> "" Then
    	Response.Write "You are a member of this site!"
    Else
    	Response.Write "Please login or register"
    End If

  6. #6
    SitePoint Enthusiast hombre_de_las_ca's Avatar
    Join Date
    Apr 2005
    Location
    Bangalore, India
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    some systems have a problem accepting cookies....safer bet will be the session
    both Bullschmidt and ZuLuuuuuu have given some very good tips
    Don't ask what your Country can do for you,
    Ask what you can do for your Country.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •