最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

can i store a cookie value set from javascript into a php variable? - Stack Overflow

programmeradmin3浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 7

Create 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.

发布评论

评论列表(0)

  1. 暂无评论