0

我的网站存在“访问”外部页面的问题。问题在于创建 cookie,我的脚本尝试在第一次访问时创建 cookie。当从外部页面(如 W3C)读取页面时,我得到了重定向循环。那么我如何只能header("location:*");在浏览器中执行。

4

3 回答 3

2

不做具体案例。一视同仁。您将很难进行“检测”。

在重定向上添加 GET 参数。并且当参数存在时不再重定向。

于 2012-08-21T07:11:00.647 回答
1

Not all browsers will accept cookies. Not all things that are not browsers will reject cookies. Trying to use the type of user agent to guess if it will accept your cookies is doomed to failure.

Change your workflow instead:

  1. Redirect to the set-a-cookie page
  2. Set a cookie
  3. Redirect to a different is-there-a-cookie page
  4. Display error message or redirect to the page they came in on

Better yet, don't require cookies until cookies are actually required (which is probably "When the user logs in" rather then "When you want to start gathering analytics data"). Note that the preceding sentence includes some largish assumptions.

于 2012-08-21T07:13:19.010 回答
0

通过使用“用户代理”字符串,您可以轻松地阻止代码在条件语句下执行。

echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";
于 2012-08-21T07:10:04.563 回答