iconicCreator Posted June 20, 2009 Share Posted June 20, 2009 I have a script, (Javascript) attached to my page. This script basically process a style sheet switcher that applies different style sheets to the page based on the users choice. This is my problem and I have tried all I know. I need the page to go back to the default style when the user closes the browser. How to do this? I have no idea! What I understand is that I have to find a way to remove/delete/distroy cookies when the user closes the browser. So that when they return, the page is back to normal style. Is it possible to use PHP to destroy/delete the cookies created by this script? Or are these cookies saved to my computer hardrive? If so, then how? Thanks everyone for your time a patience. IC Quote Link to comment Share on other sites More sharing options...
SetToLoki Posted June 20, 2009 Share Posted June 20, 2009 I have a script, (Javascript) attached to my page. This script basically process a style sheet switcher that applies different style sheets to the page based on the users choice. This is my problem and I have tried all I know. I need the page to go back to the default style when the user closes the browser. How to do this? I have no idea! What I understand is that I have to find a way to remove/delete/distroy cookies when the user closes the browser. So that when they return, the page is back to normal style. Is it possible to use PHP to destroy/delete the cookies created by this script? Or are these cookies saved to my computer hardrive? If so, then how? Thanks everyone for your time a patience. IC do you have to use cookies could you not use $_SESSION['name'] instead? $_COOKIES['name'] are persistent (and tasty) where $_SESSION['name'] timeout shorty after user leaves - dependant on php.ini settings and browser I belive Quote Link to comment Share on other sites More sharing options...
SetToLoki Posted June 20, 2009 Share Posted June 20, 2009 though <? unset($_COOKIE['name']); ?> will unset a cookie not sure where you will call it if they have already closed the browser though Quote Link to comment Share on other sites More sharing options...
SetToLoki Posted June 20, 2009 Share Posted June 20, 2009 lol I am tired and keep having after thoughts when cookies are stored on the clients harddrive, they are dependant of the clients pc. if a client uses your script which I assume sets cookies based on their style choice the page will look like that for them only untill they delete the cookie or connect from a different pc. the page will only look like that for them and not others that connect. if you wanted to avoid this (they would need to change the style each time) you could use a small function to delete all the cookies before the page loads. either using javascript or the unset function I mentioned above. Quote Link to comment Share on other sites More sharing options...
iconicCreator Posted June 20, 2009 Author Share Posted June 20, 2009 lol I am tired and keep having after thoughts when cookies are stored on the clients harddrive, they are dependant of the clients pc. if a client uses your script which I assume sets cookies based on their style choice the page will look like that for them only untill they delete the cookie or connect from a different pc. the page will only look like that for them and not others that connect. if you wanted to avoid this (they would need to change the style each time) you could use a small function to delete all the cookies before the page loads. either using javascript or the unset function I mentioned above. Thanks very much for you time, However, as I mentioned, the page does not contained a PHP variable, ad I'm just confused, Because it's running a javascript script. So how do I set a name? What will be a cookie/session be named? That's where I'm confused as to what will be the session name or cookie name, sine I have no PHP variable. IC Quote Link to comment Share on other sites More sharing options...
SetToLoki Posted June 20, 2009 Share Posted June 20, 2009 lol I am tired and keep having after thoughts when cookies are stored on the clients harddrive, they are dependant of the clients pc. if a client uses your script which I assume sets cookies based on their style choice the page will look like that for them only untill they delete the cookie or connect from a different pc. the page will only look like that for them and not others that connect. if you wanted to avoid this (they would need to change the style each time) you could use a small function to delete all the cookies before the page loads. either using javascript or the unset function I mentioned above. Thanks very much for you time, However, as I mentioned, the page does not contained a PHP variable, ad I'm just confused, Because it's running a javascript script. So how do I set a name? What will be a cookie/session be named? That's where I'm confused as to what will be the session name or cookie name, sine I have no PHP variable. IC a cookie is a cookie regardless of what creates it. if your javascript created a cookie called hello like so document.cookie = 'hello = world'; your php cookie would be called $_COOKIE['hello']; Javascript Erase Cookie for cookie named hello function eraseCookie(name) { createCookie(name,"",-1); } eraseCookie(hello) PHP erase cookie unset $_COOKIE['hello']; so at the start of your page you could use <?php function DeleteCookie ($name) { if (isset($_COOKIE[$name])) { unset($_COOKIE[$name]) } } DeleteCookie("CookieOne"); DeleteCookie("CookieTwo"); ?> //If this is only thing that sets cookies you could just grab and delete all cookies <? function DeleteAllCookies() { if (isset($_SERVER['HTTP_COOKIE'])) { $cookies = explode(';', $_SERVER['HTTP_COOKIE']); foreach($cookies as $cookie) { $parts = explode('=', $cookie); $name = trim($parts[0]); unset($_COOKIE[$name]) } } DeleteAllCookies(); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.