zang8027 Posted February 12, 2009 Share Posted February 12, 2009 If i create a cookie in javascript that holds a certain value, can i access the same thing with php? I want to create a cookie from a session.. so like.. $user = $_SESSON['priv']; and i want to create a cookie that contains the value $user. But I am using javascript to find out if cookies are enabled or not. If they are, i would like to create a cookie. So my code block is like: <script type="text/javascript"> if(!window.navigator.cookieEnabled){ alert('Please enable cookies to continue'); }else{ [CREATE A COOKIE HERE FROM THE PHP SESSION VALUE] } </script> the reason i am doing this is because for some reason, my session is being messed up when you leave my site but enter it again Quote Link to comment https://forums.phpfreaks.com/topic/144970-jsphp-work-together-with-cookies/ Share on other sites More sharing options...
Maq Posted February 12, 2009 Share Posted February 12, 2009 Yes, if a cookie is created, you can access it with any language that supports cookies. Have you tested it? Quote Link to comment https://forums.phpfreaks.com/topic/144970-jsphp-work-together-with-cookies/#findComment-760739 Share on other sites More sharing options...
zang8027 Posted February 12, 2009 Author Share Posted February 12, 2009 no cause how do i make the cookie in a javascript block that uses some php? Quote Link to comment https://forums.phpfreaks.com/topic/144970-jsphp-work-together-with-cookies/#findComment-760760 Share on other sites More sharing options...
Maq Posted February 12, 2009 Share Posted February 12, 2009 Surround your code with PHP tags and read this. Quote Link to comment https://forums.phpfreaks.com/topic/144970-jsphp-work-together-with-cookies/#findComment-760765 Share on other sites More sharing options...
samshel Posted February 12, 2009 Share Posted February 12, 2009 Javascript is a client side language, while PHP is server side... when page is displayed in the browser, PHP's job is already done. Javascript's job starts there after. so you cannot execute a PHP code directly depending on condition checked in JS. however to achieve this, you can check condition in JS and redirect the user if cookie is set to another PHP page, which will set the cookie. hope it is clear. Sam Quote Link to comment https://forums.phpfreaks.com/topic/144970-jsphp-work-together-with-cookies/#findComment-760803 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.