Hi,
i want to create a cookie using javascript but also being able to read it with php. Is it possible? for example:
Thank you.Code:In javascript:
create cookie called session
In php:
if(session cookie exists) { echo "whatever"; }
Printable View
Hi,
i want to create a cookie using javascript but also being able to read it with php. Is it possible? for example:
Thank you.Code:In javascript:
create cookie called session
In php:
if(session cookie exists) { echo "whatever"; }
Forget that question, i just found out it is indeed possible and how to do it. However now i need to make the cookie get cleared as the user leaves the page where it was created. Can you give me a hint?
Thank you.
Okay, i figured out the answer to my last question too. Now i have a new problem. I used the codes below and they work fine in firefox and chrome, but as usual not in Explorer (its a piece of ****, you know)
I would appreciate a cross-browser solution.Code:<script>document.cookie ='chat=sesion; path=index.php';</script>
<script language="javascript">
function clearCookie(){
document.cookie='chat=;expires=Thu, 01-Jan-70 00:00:01 GMT;';
}
window.onunload = clearCookie;
</script>
Thanks.
I'm not totally sure but perhaps IE requires some sort of required format? For testing purposes, use this code to set a cookie (taken from w3schools' website),
Code:function setCookie(c_name,value,exdays) {
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
Thank you, i had already fixed. You have to use path=/ instead of path=index.php.
Sorry again but for some reason tis code is not working anymore:
its supposed to clear the cookie named chat when closing the window but its not clearing it. Could you show me an alternative?Quote:
<script language="javascript">
function clearCookie(){
document.cookie ='chat=; path=/';
}
window.onunload = clearCookie;
</script>
Thank you.
Sorry, i think i should have specified that i need the cookie to be deleted as either the TAB or the window is closed.