Results 1 to 12 of 12

Thread: Check Cookies OnLoad

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    679

    Check Cookies OnLoad

    I need some assitance on this one...

    I am atttempting to use the users cookies to launch an online quize...

    I work within an Intranet, and I need to have a page recognize a specific user...Basically , like using an If statement..(i.e If user cookie = 'S526960' then open this HTML page)

    I know that is a crude example, but hopefully it gets my point accross.

    So is this possible, and if so could someone point me in the right direction to accomplish it?

    Thank you.

  2. #2
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    what format did you store your cookie in?
    eg, user_name="123435", or "12345", or maybe it also holds other data.

    (i.e If user cookie = 'S526960' then open this HTML page)
    Are you really going to make a different page for every user?
    Have I helped you? Please Rate my posts.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    679
    Well this is why I am inquiring here....I thought that I could put code in , let's say the main page, and if a specific user went to this page, I could Identify them by thier cookie, and then launch a specific page...

    Does this sound doable?

    Also I am not sure how the cookies are stored...I am in the preliminary stages of this process...do you know where I can go to find this out?

    Thanx

  4. #4
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    ok, this is untested code for you see how things work and what needs to be doen:
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function set_cookie(string) {
    document.cookie = string
    }
    
    function read_cookie() {
    var coo = document.cookie
    alert(coo)
    }
    </script>
    </head>
    <body>
    Note: This code is <b>Un</b>Tested.
    <input type="text" id="wee" value="Enter text that you want in cookie here">
    <input type="button" value="Set cookie" onClick="set_cookie(document.getElementById('wee').value">
    <br>
    <input type="button" value="alert the value of the cookie" onClick="read_cookie">
    </body>
    </html>
    If you still need help, just ask
    Have I helped you? Please Rate my posts.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    679
    It would not work... I was getting errors..."Object Expected"

    What was this for..in regards to the cookies?

  6. #6
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    oh, I see what it was. Change:
    <input type="button" value="Set cookie" onClick="set_cookie(document.getElementById('wee').value">

    to:
    <input type="button" value="Set cookie" onClick="set_cookie(document.getElementById('wee').value)">

    I had forgotten to close a bracket.
    Have I helped you? Please Rate my posts.

  7. #7
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    and change:
    <input type="button" value="alert the value of the cookie" onClick="read_cookie">

    to:
    <input type="button" value="alert the value of the cookie" onClick="read_cookie()">
    Have I helped you? Please Rate my posts.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    679
    Ok that all worked fine...but how does this help me with my original question?

    Thank you for bearing with my ignorance...

  9. #9
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    ok, replace alert(coo) with:

    Code:
    if (coo == "xxx") // Make xxx a username
        {
        location.href = "http://www.abc.com"
        }
    That will direct the user depeneding on his cookie value
    obvisouly you can have lots of IFs for lots of users. Or you could replace the whol IF with:
    location.href = coo + ".html"

    which will send user xyz to xyz.html and user abc to abc.html etc.

    Now you have to get the user to store their user name in a cookie.
    Have I helped you? Please Rate my posts.

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    679
    Ok...let's make sure that I have this right...I have to first find a way to get each user to store a specific code in a cookie so that I can use that to prompt them to a specific page?

    Am I on the right track?

    If so let me continue...I guess by way of a prompt at the beginning of the page to ask for their login, and then it will direct them to the page based on their cookie...

    Hmmmm....I like it, but Is there a way to identify a specific user without them creating their cookie?

    What I mean is...Like in our NT environment, I can use code to identify the user based on their intial Login to the NT workstation...is their a similar area within their Intranet environment that differentiates one user from another?

    I'll hang up and listen

  11. #11
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    Ok...let's make sure that I have this right...I have to first find a way to get each user to store a specific code in a cookie so that I can use that to prompt them to a specific page?
    right

    Like in our NT environment, I can use code to identify the user based on their intial Login to the NT workstation...is their a similar area within their Intranet environment that differentiates one user from another?
    Hmm. JavaScript cannot read the registry. Maybe you could make an app which makes an .js file whwnever the user logs in which holds their username. the .js file could contain:
    var un = xxx //xxx=the username


    the script could then read this file and re-direct the user. I don't know how to make the application, ask on general vb questions.
    Have I helped you? Please Rate my posts.

  12. #12
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    this might not be a good idea.

    Another user could change their .js file to contains some1 elses username. This way they could access the other persons start page. If you plan on storing e-mails etc. here, this might not be a good idea.

    Maybe take a whole new approach:
    Make a vb app that chages the start page of the user. Lits say their start page becomes:
    http://10.101.0.10/12345.html

    then it blocks all other http://10.101.0.10/*.html files

    This would be hard to make but much more secure.

    Ask on General VB Questions how else you could do it.
    Have I helped you? Please Rate my posts.

Posting Permissions

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



Click Here to Expand Forum to Full Width