SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cookie doesn't work from all folders

    I have a script which sets this cookie when you log in:

    PHP Code:
    setcookie('username'$usertime() + (86400), '/'); 
    However, when I try to check if the cookie is set with another script located in another folder on my domain, it acts if the cookie isn't set.

    Doesn't the '/' function when setting a cookie, mean that it should be accessable from all folders on my domain? If not, what is the correct function to use?

  2. #2
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you have the right code there it looks like. when you go to the other folder, is it the exact same domain? www.domain.com and domain.com are not the same.

    you could also try setting the 5th domain parameter as ".domain.com" and see if that works.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  3. #3
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, it is the same domain.
    The script that sets the cokkie is located in something like www.domain.com/features/novels/ and the script I am working on which should use the same cookie is in www.domain.com/admin/

    I tried using '.domain.com' but then the cookie doesn't work properly, so I set it back to '/'

  4. #4
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no, i meant putting the domain as an additional parameter. like this

    PHP Code:
    setcookie('username'$usertime() + (86400), '/''.domain.com'); 
    other than that i don't know. as far as i know that cookie should work the way you have it already.

  5. #5
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It works now
    Thanks!

  6. #6
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cool. but that's weird. i thought i'd tell ya to try that, but didn't think it would make a difference... i thought that the browser would automatically use the current domain.

    can anybody confirm how it's supposed to work? probably not, but i thought i'd ask.

    anyway, glad it's working at least.


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
  •