Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/453.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 只重定向一次文件_Php_Javascript_Session_Cookies - Fatal编程技术网

Php 只重定向一次文件

Php 只重定向一次文件,php,javascript,session,cookies,Php,Javascript,Session,Cookies,可以重定向到一个文件2次,然后第三次重定向到其他地方 例如:/index.php重定向到/index2.php,然后/index2.php重定向到/index.php…,,,那么第二次访问/index.php时,它会将我们重定向到其他文件吗 我们可以用javascript或PHP实现这一点吗?index.PHP重新定义为index2.PHP index2.php重定向到index.php?r=1 在index.php中检查: if($_GET['r']==1){ //redirect t

可以重定向到一个文件2次,然后第三次重定向到其他地方

例如:/index.php重定向到/index2.php,然后/index2.php重定向到/index.php…,,,那么第二次访问/index.php时,它会将我们重定向到其他文件吗


我们可以用javascript或PHP实现这一点吗?

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>

如果(document.referer==“site.com”){
location.href='其他页面地址';
}
否则{
location.href='site.com';
}

因此,如果用户来自其他站点,当他从site.com转到其他位置时,他将重定向到site.com。

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


当计数器达到极限时,执行所需操作。

是,您可以。问题是你想要多长久

JAVASCRIPT:

如果你想用javascript来做,那么看看
窗口位置
要记住用户是否在第一页,只需使用JavaScript cookies即可。 简单教程 您还可以设置过期时间

PHP:

如果您想让它“不那么永久”,例如只针对一个打开的浏览器窗口或类似的东西,那么请查看PHP会话管理
我已经为index.php?re\u 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");
     }
}

抱歉,我想我问了一个错误的问题,我只能控制1个重定向,所以我只能控制1个文件,例如:重定向到mysite/index.php,然后mysite/index.php重定向到site.com/redirect1,所以现在我使用javascript重定向setInterval(function(){document.location=“site.com/redirect1”},3500);但这就像是一个轮子里的松鼠:用别针固定这个箱子,你可以使用
document.referer
并检查它是否从site.com重定向到其他地方。你不需要计数器。我更新了问题,如果我理解错了,请告诉我。由于未知原因,无法检测到document.REFERER我如何组合url+document.location.hash.slice您可以始终使用PHP
$\u服务器['HTTP\u REFERER']
变量()我只能控制1个文件,所以这仍然是可能的?如果已经从另一个文件设置了头,我们仍然可以设置另一个头吗?在我的代码中包括('main.php');设置$\u会话[计数器]=0;在重定向之前,按如下方式递增计数器:$_SESSION[counter]+=1;标题('Location:index.php');现在,在另一个页面上,您可以检查会话变量的值。我只能控制一个文件,是否可以将两者合并到一个文件中?