我的根文件下有一个文件夹,我试图通过使用cookie 来限制对该文件夹的访问
我想要的是基于cookie值重写重定向
例如,在我的htaccess中,我有这个
RewriteEngine On
// check if cookie is set and is equal to script.php
RewriteCond %{HTTP_COOKIE} ^(.*)mycookie=[script.php] [NC]
// allow access if above condition is met [ which i cant figure out how to implement]
RewriteRule ^ http://example.com/folder/index.html [NC,L]
// or if the conditions above are not met rewrite somewhere else
下面是我希望它如何工作
当用户单击此url时。。http://example/contents/folder/index.html,服务器应检查mykokie是否已设置并等于script.php文件返回的变量,然后如果满足条件,则让它们进入或重写到另一个url
script.php返回数据库中的一个变量每次用户登录并更新数据库中的行字段时都会生成此变量,以防止重用cookie变量。这意味着一个人将无法通过设置自己的变量或在其他地方复制和重用cookie来操作cookie。
script.php中的所有内容都得到了处理,我的问题是htaccess文件。请帮助
我在评论中建议您的.htaccess只需拦截请求并将其转发到script.php文件。然后是您的脚本负责验证cookie以及最终显示的内容。
RewriteRule ^folder/index'.html$ /folder/script.php [NC,L]
现在,在php中,相应地验证cookie和include或重定向。
<?php
if (isset($_COOKIE["myCookie"]) && verifyCookie($_COOKIE["myCookie"])) {
include 'index.html';
} else {
header ("Location: http://domain.com/some/other/page.php");
}
?>