Hey everyone,

When i use the setcookie function it works fine on my localhost but when i upload it to my remote web server i power web the cookie never sets on the users browser. I have all security down on my broswer and it still does not set. What am i doing wrong.

    posting code would be helpful ..

      I use www.ipowerweb.com for my hosting, too, but I don't have any problems setting cookies, so the glitch must be elsewhere.

      As seby said, we will need to see the code you are using.

        all i have is a number coming from a get var that i would like to put into a cookie so it looks something like this.

        $room_id = $_GET['room_id'];
        setcookie("room_id",$room_id,time()+3600);

          what php version are you using?

          try this:

          setcookie("room_id",$room_id,time()+3600);

          it probably has to do with one server having globals on and the other off.

            whats different about your code and mine if i may ask?
            They look the same to me.

              i left out the get var.

              also try setting a cookie path, something like:

              setcookie("Test", $value,time()+3600, "/tmp", ".domain.com");

                I think the problem is in your expiration time.

                You are setting the cookie to expire in 1 hour, right?

                The IPoweWeb server is located in Los Angeles, California. If it is 5:00 PM there, then it will set the expire time for 6:00 PM.

                If you live in the great state of Texas, then, when it is 5:00 PM in California, it is 7:00 PM in Texas, due to time zones.

                Since the server set the cookie to expire at 6:00 PM, the browser will consider the cookie to be expired, and therefore will not set it!

                Obviously, this would not be a problem running on your localhost. 😃

                HTH

                  Thanks guys, hey can you tell me also how to turn this dang warning off
                  Warning: Unknown(): Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0

                    Cookies are, according to the standard, normalized to GMT, and time zones should not be an issue.

                    However, since the server creates the timestamp and the client interprets it, the mechanism does rely on the server's clock and the client's clock being reasonably accurate and both machines having correct notions of their own timezones.

                    If either the server or the user's computer is misconfigured, that could cause the time not to match.

                    Revert to your original code. Up the value you are adding to time() by an order of magnitude. If the problem goes away, you've verified that timestamp matching is the problem.

                    Then start doing some detective work with your hosting company.

                      mwichmann4,

                      I'm unfamiliar with that warning, so I'm no help there.

                      Hope the cookie/time stamp thing works out, though.

                      Good Luck!

                        Write a Reply...