#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    1
    Rep Power
    0
    hello

    I'm working on a Usersystem, and currently it works kind-of like this:

    the user logs on on the net,
    form method=post action=$php_self)
    when the username/password was sent, it calls the function to check username/password, if they match with those in the database, a cookie is set containing the password md5 encrypted and some additional information (like group the user is in).
    I've made everything with one if-loop...
    before it enters the if-loop, the verification function is called, afterwards it enters the if loop, checks to which group the user belongs (reads it from the cookie). If the cookie isn't set, it prompts the user the login form.

    My problem is that it seems like the cookie isn't set fast enough because it prompts the user to login again. If loging in again, everything works fine. the cookie gets set the first time you login.

    I'm asking myself now what may cause this, if anyone already had a similar problem and if yes, how he got around with it.
    I don't like the idea of splitting the login-, verification- and 'main'-part(s) of the script into 3 different files. But if there's no workaround for that... If you want to see the source code, drop me an e-mail and I'll send it to you.

    greetings

    emanuel nacht
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    18
    Cookies aren't available in the process in which they are set. Consequently, your cookie won't be available until the 3rd time thru the process:

    1) No cookie - display login
    2) Process login - set cookie
    3) cookie available from here forward

    What you should do is set a flag when the cookie is set so that the script "knows" that it already has the cookie value (because it just set the value) and doesn't need to read the cookie.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 1999
    Location
    Annapolis, Maryland US
    Posts
    113
    Rep Power
    15
    I got this from PHP's website...

    >>Cookies will not become visible until the next loading of a page that the cookie should be visible for.

    Unfortunately, the only workaround I've found is exactly the one you don't want to do, which is splitting up the login process into three different pages
    1. Login page
    2. Process login information and set cookie in second script page
    3. Test cookie existence in third script page and redirect user to either accessible page or back to login form/possibly a page telling them that cookies need to be used.

    I, too, would like to know of any other workarounds other than the above.
  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    18
    I don't see why this is such a problem.

    Why does the process that sets the cookie have to read it???

    Do you have scripts that read a record from a db table that was just written by the same script?

Similar Threads

  1. cant delete cookies random errors
    By toxical in forum PHP Development
    Replies: 2
    Last Post: November 26th, 2003, 05:16 AM
  2. Clearing all cookies php script - HowTo?
    By fordfasterr in forum PHP Development
    Replies: 8
    Last Post: October 24th, 2003, 09:40 AM
  3. Problem with lwp and cookies
    By vinaykakade in forum Perl Programming
    Replies: 1
    Last Post: August 13th, 2003, 10:07 AM
  4. Problems setting cookies with a path and domain
    By IBBoard in forum PHP Development
    Replies: 4
    Last Post: July 2nd, 2003, 03:03 PM
  5. AOL cookies?
    By cfthong in forum PHP Development
    Replies: 0
    Last Post: August 18th, 2000, 10:59 AM

IMN logo majestic logo threadwatch logo seochat tools logo