0

是否可以重定向到文件 2 次然后第三次重定向到其他地方

EX:/index.php 重定向到 /index2.php 然后 /index2.php 重定向到 /index.php .....,,, 然后我们第二次访问 /index.php 它会将我们重定向到其他文件?

我们可以用 javascript 或 PHP 做到这一点吗?

4

4 回答 4

1

index.php重定向到index2.php

index2.php重定向到index.php?r=1

在 index.php 检查:

if($_GET['r']==1){
    //redirect to other page
}

更新

据我了解,您有以下重定向:

1. Somewhere => index.php
2. index.php => site.com
3. site.com  => index.php // and in this step you need to redirect to other place

所以只需添加检查:

<script type="text/javascript">
if(document.referrer == 'site.com'){
    location.href = 'OTHER PAGE ADDRESS';
}
else{
    location.href = 'site.com';
}
</script>

因此,如果用户来自其他站点,如果他从 site.com 到其他地方,他将重定向到 site.com。

于 2013-03-20T11:35:02.750 回答
0

是的,您可以在会话变量中添加一个计数器来跟踪重定向。每次重定向后,递增计数器。

当计数器达到其极限时,执行您想要的操作。

于 2013-03-20T11:35:49.917 回答
0

是的你可以。问题是你想要它有多永久。

JAVASCRIPT:

如果您想使用 javascript 进行操作,请查看 window.location 并记住用户是否在第一页上,只需使用 JavaScript cookie。简单教程http://www.tutorialspoint.com/javascript/javascript_cookies.htm 还可以设置过期时间。

PHP:

如果您想让它“不那么永久”,例如仅针对一个打开的浏览器窗口或类似的东西,请查看 PHP 会话管理 http://php.net/manual/en/features.sessions.php

于 2013-03-20T11:39:21.480 回答
0

我已经编写了 index.php?re_id = 的代码

在每个页面上提及 re_id。n 你可以给出更多条件

 if($_GET['re_id']){

     $re_id = $_GET['re_id'];   
      if($re_id=="1")
      {
      header("location:index3.php");
      }
      else
      {
         header("location:index2.php");
     }
}
于 2013-03-20T11:47:23.320 回答