Jump to content

JavaScript, cookie and SAFARI


djp1988
 Share

Recommended Posts

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

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

one for PHPSESSID I don't know why, I have not made a session
Apparently 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

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

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

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...