简单的要求;我需要访问我网站的访问者才能查看该网站。当用户访问 my.site.com/anydirectory/anypage.php 时,需要将其重定向到 my.site.com/index.php 会给予警告并选择离开或继续。如果他们继续,则设置cookie并将其带到最初请求的页面(最终可访问整个站点,至少90天)。如果他们选择Walk Away,则会设置不同的Cookie并将其重定向到 my.site.com/bummer.php ,并将继续定向到< strong> bummer.php 页面,直到90天结束或他们删除cookie,以先到者为准。
这就是我所拥有的;
我把它放在我所有页面的顶部......
<?php if (!isset($_COOKIE['youwerewarned'])) {
header("Location: /index.php?url=http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]")
}
?>
...然后我把它放在 index.php 页面的顶部......
<?php
// change to your domain name.
$domain = "my.site.com";
// Get the requested page, add it to our domain so we can create an enter link
if (isset($_GET['request'])) {
$request ="<a href='http://$domain" . $_GET['request'] . "'>";
}
// The exit link
{
$leave ="<a href='http://my.site.com/bummer.php'>";
}
// Set a cookie so we are not redirected back here again. You can set how long the cookie is good.
if (!isset($_COOKIE['youwerewarned'])) {
setcookie('youwerewarned','true',time()+6048... . $domain);
}
?>
...然后我把它放在适当位置的 index.php 页面中......
<?php echo $leave ?>WALK AWAY</a> <?php echo $request ?>CONTINUE</a>
......我错过了什么?
答案 0 :(得分:0)
我可以告诉你,你错过了一个结束/结束分号:
header("Location: /index.php?url=http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]")
做的:
header("Location: /index.php?url=http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
然后有这条线,我不知道这是否=&gt; ... .
是您实际代码的一部分。
setcookie('youwerewarned','true',time()+6048... . $domain);
应该读作
setcookie("youwerewarned", "true", time()+6048, "/", $domain);
开启error reporting会发出信号
解析错误:语法错误,意外'}',期待','或';'在第X行的......(文件路径)
缺少分号。