lets say that I have sub1.domain.com and sub2.domain.com. When I set a cookie in sub1.domain.com I need to be able to read it in sub2.domain.com. I tried setting the domain value in setcookie to "domain.com" and ".domain.com" and both times it just appended what i wrote to "sub1.domain.com". So i ended up with the domain on the cookie being: "sub1.domain.com.domain.com". Anyone know what I can do to be able to read a cookie set from another subdomain?

Thanks
-Shawn

    • [deleted]

    the domain should be set to whatever you tell it to be.

    What is the code you are using to set the cookie?

      setcookie(variable,"value","time", ".domain.com")

      is that wrong? =)

        • [deleted]

        That looks quite alright.

        How did you find out that the domain gets appended to the whole domain?

        Just for reference, did you try any of the alternative set-cookie methods mentioned in the annotations to the manual?
        http://www.php.net/manual/en/function.setcookie.php

          Yup.. tried everything.. i just opened the cookie that it sets locally here in notepad.. ... i tried to print cross-subdomain cookies for testing, and nothing came up.. i'm really stumpted with this one.

            STUPID me.. didn't even realize what was going on... i didn't pass the "" needed for the path, so the domain was appended to the URL because it was being passed to the setcookie function as the path... oh well.. fixed now.. thanks for your help!

              Write a Reply...