javascript – 使用php中的cookie保存变量

在过去的两周里,我一直致力于在cookie中保存页面ID,然后在其他页面中检索它.

最后我解决了它,但现在我有一些其他问题我想在我的PHP代码中使用这个id(我在cookie中保存并检索它).

我知道javascript是客户端代码,PHP是服务器端代码,但我必须这样做.这个你能帮我吗.

这是我的javascript代码,它工作得很好,我得到了这行“value.favoriteid”的已保存ID

arat(0) === ' ') {
        cookie = cookie.substring(1,cookie.length);
      }
      if (cookie.indexOf(nameEQ) === 0) {
        return cookie.substring(nameEQ.length,cookie.length);
      }
    }
    return null;
  }
  function eraseCookie(name) {
    createCookie(name,"",-1);
}
    var faves = new Array();
$(function(){
    var favID;
    var query = window.location.search.substring(1);

	var vars = query.split("&");
    for (var i=0;i
最佳答案
PHP端读取cookie,用js设置它们是最容易的事情.

Any cookies sent to you from the client will automatically be included
into a $_COOKIE auto-global array if variables_order contains “C”. If
you wish to assign multiple values to a single cookie,just add [] to
the cookie name.
Depending on register_globals,regular PHP variables can be created
from cookies

这里的PHP是一些例子:

PHP 
echo $_COOKIE["your cookie name"];
?>

PHP
print_r($_COOKIE);
?>

It’s not recommended to rely on them as this
feature is often turned off for the sake of security.

http://php.net/manual/en/features.cookies.php

相关文章

前言 做过web项目开发的人对layer弹层组件肯定不陌生,作为l...
前言 前端表单校验是过滤无效数据、假数据、有毒数据的第一步...
前言 图片上传是web项目常见的需求,我基于之前的博客的代码...
前言 导出Excel文件这个功能,通常都是在后端实现返回前端一...
前言 众所周知,js是单线程的,从上往下,从左往右依次执行,...
前言 项目开发中,我们可能会碰到这样的需求:select标签,禁...