anujgarg Posted August 3, 2008 Share Posted August 3, 2008 I am trying to retrieve cookies in PHP that were earlier set in javascript. How can I do it? Link to comment https://forums.phpfreaks.com/topic/117931-getcookies-from-javascript-to-php/ Share on other sites More sharing options...
PHPTOM Posted August 3, 2008 Share Posted August 3, 2008 at start of the document put ob_start(); then echo $_COOKIE['cookiename']; ---------------- Now playing: Sugarland - Stay via FoxyTunes Link to comment https://forums.phpfreaks.com/topic/117931-getcookies-from-javascript-to-php/#findComment-606605 Share on other sites More sharing options...
PFMaBiSmAd Posted August 3, 2008 Share Posted August 3, 2008 A browser automatically sends cookies to the web server (where php can access them in the $_COOKIE array) that have settings that match the http/https protocol, hostname, domain, and path of the URL that is being requested and javascript cannot access any cookie that does not have settings that match the current page the javascript is running on due to the "same origin" security - http://en.wikipedia.org/wiki/Same_origin_policy So, matching cookies are already available to php and non-matching cookies cannot be accessed anyway. What exactly are you trying to do? Link to comment https://forums.phpfreaks.com/topic/117931-getcookies-from-javascript-to-php/#findComment-606666 Share on other sites More sharing options...
LemonInflux Posted August 3, 2008 Share Posted August 3, 2008 I had a situation like this a while back, where I wanted a javascript CSS stylesheet switcher that sets a cookie, that could then be picked up by PHP on other pages. I never found a solution though ---------------- Now playing: Dance Gavin Dance - 12 Hours, 630 Miles via FoxyTunes Link to comment https://forums.phpfreaks.com/topic/117931-getcookies-from-javascript-to-php/#findComment-606692 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.