使用php在htaccess中重写url后,无法在页面加载时从cookie检索数组
我正在将cookie设置为:使用php在htaccess中重写url后,无法在页面加载时从cookie检索数组,php,.htaccess,cookies,Php,.htaccess,Cookies,我正在将cookie设置为: Options +FollowSymLinks -MultiViews RewriteEngine on RewriteBase /roots_web/ RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ http://%1/$1 [R=301,L] RewriteRule ^contact-us.html/$ contact-us.php RewriteRule ^contact-us.ht
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /roots_web/
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule ^contact-us.html/$ contact-us.php
RewriteRule ^contact-us.html$ contact-us.php
当我转到另一页检查时
setcookie("reports_cookie[".$report_id."][report]", $report_id);
它不会将此情况评估为真。请确保
if(isset($_COOKIE['reports_cookie']) && count($_COOKIE['reports_cookie'])>0)
{
}
在对浏览器进行任何输出之前使用
比如说
setcookie("reports_cookie[".$report_id."][report]", $report_id, time()+3600,"/");
另外,请思考为什么要将报表ID存储为数组键和值…请在问题中添加说明,而不仅仅是代码。你到底在问什么?我在一个页面上设置了一个cookie,我在两个页面上使用它。这在早些时候很管用。但在我重写ht ACCESS文件中的URL后,我无法在其他页面上获取cookie。这表明未设置Cookie。这不足以调试或从中推断此行为。显示如何在第一页中调用、浏览器存储它的属性(域、路径、过期时间)或某些devtools网络HTTP请求检查.setcookie(“reports\u cookie[“$report\u id.”][report]”、$report\u id);请不要在对您的问题的评论中添加其他信息。而是编辑你的问题。你自己的兴趣是让这个问题尽可能容易阅读和理解,这样你就能得到好的和有用的回答。您的问题下方有一个
编辑链接。用它!
<html>
<head>
<title>
hello world
</title>
</head>
<?php
setcookie("reports_cookie[".$report_id."][report]", $report_id, time()+3600,"/");
?>
</html>
<?php setcookie("reports_cookie[".$report_id."][report]", $report_id, time()+3600,"/");
^-- a space making your cookies fail
setcookie("reports_cookie[".$report_id."][report]", $report_id, time()+3600,"/");