after I moved data to new server, my authentication script does not work, it says "thank for looging" but when it proeced, to the next pages it asks toe re-login.. after sending a lot of time, I am not sure if its a script error or the server. the same script works great on MANY other servers but not on tihs speciic server. after spending almost 3 hours, I have foudn that if I add time() to the cookie, its not saved, but if time() is not added cookie is saved.. thi works fine setcookie ("cName", "cookieone"); but this does not work setcookie ("cName", "cookieone", time()+3600); my code for loggin user is $val has different values, I just put random here to give u an idea.. $val = "1,ss"; $cdomain = ".mysite.com"; if(!setcookie('user',$val,time()+ (3600*24),'/',$cdomain)) echo 'Please set your browser cookies ON, in order to log in.'; else { echo "successfuly logged, redirecting to blah blah blah..."; } Code (markup): can anyone tell me what could be wrong ? this script works fine on other server, but this server has PHP Version 5.2.4 thanks for your time..
No user will ever see the "Please enable cookies" text. The cookie header will be sent to the browser, regardless of the browser settings. This behavior is only logical under one condition. The server is set to a different timezone than your browser. And the time difference seems to be big. The first cookie works because if you don't specify an expiry date, it'll automatically be deleted when the browser is closed. The second does not work because it's set to a time prior the current one, and it's being deleted by the browser right after receiving it. Try increasing the cookie time expiry date.
I don't sure I think that you have moved to a host where the servertime is different from the previous ones. The time is not the same all over the world so say that the server is in on a place where the clock is 2:00 pm but where you are the time is 5:00 pm that means if the server sets the cookie to expire in time()+3600 that means at 3:00 pm but that has already past time for you and the cookie will not be set. I think it works like that. In your code you set the cookie to expire in a 24 hours so it should be a problem but are you sure that the server time is correct? Check if time() returns the right time.
thanks for the replies, my cookie time is set time()+ (3600*24) I think thats 24 hours, so it should work if even there is difference of 6-8 hours.. the strange thing is the I can login via FireFox, but cannot login through IE.. ----------------------------------------- while writing this post, I checked the time tihng and my computer had WRONG time, it was 27th already and AM, I changed hte time and it seems to be fixed now.. but now it doesnt allow me to logout .. will report back..