I stored a javascript value into a cookie, as shown below.
var headvalue = "blue";
localStorage.setItem('headvalue', headvalue );
It it possible to get this headvalue variable from the cookie and store it into a php variable $headvalue? if yes how?
I stored a javascript value into a cookie, as shown below.
var headvalue = "blue";
localStorage.setItem('headvalue', headvalue );
It it possible to get this headvalue variable from the cookie and store it into a php variable $headvalue? if yes how?
Share Improve this question asked Feb 7, 2014 at 2:15 user3121403user3121403 1331 gold badge4 silver badges11 bronze badges 1- 2 localStorage != cookies. If it was a cookie and it was sent to the server, then yes, PHP could access it (upon the next request). – user2864740 Commented Feb 7, 2014 at 2:16
2 Answers
Reset to default 7Create the cookie with Javascript:
var headvalue = "blue";
document.cookie = "headvalue="+headvalue;
Retrieve it with PHP:
$headvalue = $_COOKIE["headvalue"];
What are you trying to do? I suppose you could do that with AJAX by calling a PHP page with GET/POST, submitting your variable and storing it, but it isn't going to do you much good after that script has pleted executing, unless you stored it as a session variable.