繁体   English   中英

根据Cookie重定向访客

[英]Redirect visitor based on cookie

我开始学习php,im建立了一个小应用程序,需要根据访问者是否具有偏好cookie来将访问者发送到特定页面,如果需要,则根据访问者cookie转到特定页面。

因此,在我的应用程序的一部分中,访问者将面临三个链接,当访问者单击链接时,将发送记录访问者偏好的cookie,以便

Link1 = Prefcookie1
Link2 = Prefcookie2
Link3 = Prefcookie3

在另一页上

如果没有重定向到index1,请检查是否有任何prefcookies

如果是,请检查哪个precookie

If prefcookie = prefcookie1 redirect to index
if prefcookie = prefcookie2 redirect to index1
if precookie = prefcookie3 redirect to index3

还是可以通过htaccess实现类似的东西?

非常感谢任何帮助,这是完成此任务的最后一件事

您可以在PHP中阅读Cookie,请参阅http://php.net/manual/zh/features.cookies.php

但是您提到htaccess,它建议您计划使用Apache中的RewriteRules来执行此操作,而后者与PHP无关。 是否可以使用RewriteRules做到这一点的答案是肯定的,尽管您将需要支持它的服务器。 请参阅http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html (有关服务器变量的部分)

PHP为此可以很好地工作:

<?
if($_COOKIE['prefcookie'] == "prefcookie1")
 {header("Location: index");}
elseif($_COOKIE['prefcookie'] == "prefcookie2")
 {header("Location: index2");}
elseif($_COOKIE['prefcookie'] == "prefcookie3")
 {header("Location: index3");}
else
 {header("Location: index1");}
?>

或者

您可以在要重定向的所有页面上插入“检查脚本”。 插入第一行。

例如:“ thefinn93”

<?
if($_COOKIE['prefcookie'] == "prefcookie1")
 {header("Location: index");}
elseif($_COOKIE['prefcookie'] == "prefcookie2")
 {header("Location: index2");}
elseif($_COOKIE['prefcookie'] == "prefcookie3")
 {header("Location: index3");}
else
 {header("Location: index1");}
?>

标清

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM