我需要查看产品购物车,并且需要通过 PHP 进行首次加载,并通过 jQuery post 进行其余查询(通过删除产品或类似内容进行更新)。
好吧,问题来了。
[我在同一个 php 文件“any.php”上通过 JSON 获取变量]
当我在 PHP 上执行第一个 isset($_COOKIE)
(通过curl)并返回 NULL 时,第一个 PHP 加载不起作用,但是..如果我调用该方法 .post("any.php")
在 jQuery PHP 上,它返回包含产品的购物车。
为了添加产品,我使用 PHP 函数
setcookie($cookieName, $createcart, $cookieExpire);
Cookie 参数:
session_set_cookie_params(
time()+3600,
'/',
'.test.com',
0,
0
);
setCookie(createcart为json值):
setcookie($cookieName, $createcart, $cookieExpire);
PHPINFO
session
Session Support enabled
Registered save handlers files user
Registered serializer handlers php php_binary wddx
Directive Local Value Master Value
session.auto_start Off Off
session.bug_compat_42 Off Off
session.bug_compat_warn Off Off
session.cache_expire 180 180
session.cache_limiter nocache nocache
session.cookie_domain .test.com.pe no value
session.cookie_httponly Off Off
session.cookie_lifetime 1379499657 0
session.cookie_path / /
session.cookie_secure Off Off
session.entropy_file no value no value
session.entropy_length 0 0
session.gc_divisor 1000 1000
session.gc_maxlifetime 1440 1440
session.gc_probability 1 1
session.hash_bits_per_character 5 5
session.hash_function 0 0
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path /var/lib/php/session /var/lib/php/session
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies On On
session.use_trans_sid 0 0
最佳答案
来自:http://php.net/manual/en/function.setcookie.php
Common Pitfalls:
Cookies will not become visible until the next loading of a page that the cookie should be visible for. To test if a cookie was successfully set, check for the cookie on a next loading page before the cookie expires. Expire time is set via the expire parameter. A nice way to debug the existence of cookies is by simply calling print_r($_COOKIE);.
关于php - Cookie 在 PHP 中不起作用,但在 Javascript 中起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18867955/