djp1988 Posted August 20, 2008 Share Posted August 20, 2008 I have a layer on my site, and when you click on it's contents, this js happens: function saveCookieinfo(){ var now = new Date(); now.setTime(now.getTime() + 1000 * 60 * 60 * 2); document.cookie = "votetime=1; expires="+now; document.getElementById("Layer1").style.display = "none";} and the php of the same page checks for this cookie, if it's there it won't render the layer, until the cookie isn't there (after 2 hours), although this works on all other browsers, I just noticed that safari isn't playing right, it would seem that the php doesn't detect the cookie, or maybe I am setting the cokkie in a way safari doesn't do?My php is the following: <?php if($_COOKIE['votetime'] != 1){echo '<div id="Layer1"><div class="voterForUs"><a href="..." onclick="saveCookieinfo()" target="_blank"><img border="0" src="..." width="90" height="50"></a><br />...</div></div>';}?> I have just noticed that in Opera the cookie seems to be killed if the browser is quit, and when you open the browser again, the layer renders, but if you don't quit, and suf the site, the cookie and php are doing what the should and the layer doesn't come back.....AND also, this forum's logo at the top, and ad on the top right, don't appear in safari nor opera on mac.... but the image source in the source of the page is there.... what's up with that ? Link to comment Share on other sites More sharing options...
justsomeguy Posted August 20, 2008 Share Posted August 20, 2008 You're using a UNIX timestamp for the cookie expiration, the expiration time should be in the format DD-Mon-YYYY HH:MM:SS GMT. Other than that, inside Safari look for the cookie to verify that it's actually being set. Link to comment Share on other sites More sharing options...
djp1988 Posted August 20, 2008 Author Share Posted August 20, 2008 in safari, after i supposidly set the cookie, in my preferences I look up this cookie, I see a cookie, but the name isn't the same, it is PHPSESSID, there is no expiration and the value of it I cannot even wonder where it came from, but strange that there is a cookie, that wasn't there before, but it isn't what I want it to beOn comparaison with firefox, I get on that 2 cookies one for PHPSESSID I don't know why, I have not made a session?? and the other is th one i want, so I am seeing that this javascript is not setting a cookie, are there diferent ways to set cookies for safari seen as htis doesn't work? Link to comment Share on other sites More sharing options...
justsomeguy Posted August 20, 2008 Share Posted August 20, 2008 one for PHPSESSID I don't know why, I have not made a sessionApparently you did, PHPSESSID is the default PHP session name. If you didn't explicitly start a session then the session auto_start config option might be enabled.http://developer.apple.com/internet/safari/faq.html#anchor6 Link to comment Share on other sites More sharing options...
djp1988 Posted August 20, 2008 Author Share Posted August 20, 2008 ok, that function works, i have cookies ! maybe it is bacause of the expiration date which you told me wasn't good? maybe safari rejects these cookies? in that case how can I dynamically set the expiration date for 2 hours time going from miliseconds to a date in the form of ../../.... Link to comment Share on other sites More sharing options...
justsomeguy Posted August 20, 2008 Share Posted August 20, 2008 The Javascript Date object has methods to do that, but the getTime method just returns a UNIX timestamp.http://devguru.com/technologies/javascript/10585.asp Link to comment Share on other sites More sharing options...
djp1988 Posted August 23, 2008 Author Share Posted August 23, 2008 i can't figure out to go from:lastlogin = HERE THE TIMESTAMP;to ../../.... Link to comment Share on other sites More sharing options...
justsomeguy Posted August 23, 2008 Share Posted August 23, 2008 You could use getMonth, getDate, getYear, etc, you could use toLocaleString or toUTCString, take a look through the methods listed on that page. Link to comment Share on other sites More sharing options...
jeffman Posted August 23, 2008 Share Posted August 23, 2008 The first method to look at is setTime(). Pass your timestamp (in milliseconds) to that, and your date object will return day, date, year, etc. for the correct day. Link to comment Share on other sites More sharing options...
djp1988 Posted August 23, 2008 Author Share Posted August 23, 2008 You're using a UNIX timestamp for the cookie expiration, the expiration time should be in the format DD-Mon-YYYY HH:MM:SS GMT. Other than that, inside Safari look for the cookie to verify that it's actually being set.Hold on, I just realised, I'm not setting the expiration date in miliseconds : function saveCookieinfo(){ var now = new Date(); now.setTime(now.getTime() + 1000 * 60 * 60 * 2); document.cookie = "votetime=1; expires="+now;} Link to comment Share on other sites More sharing options...
justsomeguy Posted August 24, 2008 Share Posted August 24, 2008 Did you alert now to see what it is? It's a date object. Link to comment Share on other sites More sharing options...
djp1988 Posted September 8, 2008 Author Share Posted September 8, 2008 yep but the cookie doesn't get saved Link to comment Share on other sites More sharing options...
justsomeguy Posted September 8, 2008 Share Posted September 8, 2008 Right, because the expire date for a cookie isn't supposed to be a Javascript date object, it's supposed to be a time stamp in a certain format. Link to comment Share on other sites More sharing options...
djp1988 Posted September 14, 2008 Author Share Posted September 14, 2008 so what do I have to change? I want the expiration date to be 2hours Link to comment Share on other sites More sharing options...
justsomeguy Posted September 15, 2008 Share Posted September 15, 2008 Create a date object, add 2 hours to it, and use something like toUTCString to get the timestamp to use with the cookie. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.