SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: Cookie Question

  1. #1
    SitePoint Evangelist rockyracoon's Avatar
    Join Date
    Apr 2003
    Location
    Burbank
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cookie Question

    Will these two lines create 2 cookies, or will the 2nd overwrite the 1st?

    setcookie("tb_sesid", $PHPSESSID, time()+3600*360, "/", ".tblog.com", 0);


    setcookie("tb_sesid", $PHPSESSID, time()+3600*360, "/", "", 0);

  2. #2
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would say it will overwrite it since they have the same name.

  3. #3
    SitePoint Evangelist rockyracoon's Avatar
    Join Date
    Apr 2003
    Location
    Burbank
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I am using mod_rewrite to change:

    www.domain.com/username

    to

    username.domain.com

    Which will cookies see?

  4. #4
    SitePoint Addict phptek's Avatar
    Join Date
    Jun 2002
    Location
    Wellington, NZ
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As long as you use two periods in the domain - the 5th arg to setcookie(), your cookie should work across the board:

    * www.sitedomain.com
    * http://sitedomain.com
    * http://subdomain.sitedomain.com


    HTH

  5. #5
    SitePoint Evangelist rockyracoon's Avatar
    Join Date
    Apr 2003
    Location
    Burbank
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Last post, sorry! So I am guessing you would prefer leaving out the "." like this:

    setcookie("tb_sesid", $PHPSESSID, time()+3600*360, "/", "tblog.com", 0);

  6. #6
    SitePoint Addict phptek's Avatar
    Join Date
    Jun 2002
    Location
    Wellington, NZ
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No - leave it in - that way the cookie will function for subdomains too (http://sub.domainname.com)

    Spend some time reading the posts at: http://uk.php.net/manual/en/function.setcookie.php - it's well worth it really (We've had some real issues which were solved by adding the second period)

    BTW - the secure cookie part of setcookie() arg 6 truly is optional...

  7. #7
    SitePoint Evangelist rockyracoon's Avatar
    Join Date
    Apr 2003
    Location
    Burbank
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have read it through and through, and 10% of my users still lose the cookie when they access http://username.domain.com/

    I will keep searching though. Thanks for your help.

  8. #8
    SitePoint Addict phptek's Avatar
    Join Date
    Jun 2002
    Location
    Wellington, NZ
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What do you mean exactly by "Lose the cookie"?

    I only ask because when we had some issues a few months back now - users couldn't login to our cookie based system after a major site overhaul, but having them delete the cookies and login again (Having changed from one period in setcookie() to two) everything worked fine.

    Sure it was hassle to have most of our users call/email in and have one of the girls or myself talk them through the whole process - but they're all happy bunnies now...

    FYI:

    IE/Win requires you delete cookies from:

    * C:\Documents and Setting\<username>\Cookies AND
    * C:\Documents and Settings\<username>\Local Settings\Temporary Internet Files

    Good luck


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
  •