smelikecat

导航

[FRAMESET][PHP]Frameset下面使用php-header('location:...') redirect链接

一般,我们的管理后台都是使用frameset来进行布局的,所以如果我们对后台的登录会话时间进行了设定,那么在超过该时间session失效之后,那么我们就必须要在php文件中进行判断处理。

判断会话失效之后,那么就应该要执行跳转到登陆页面,让用户重新再次进行登录后台。

如果我们直接使用php的header来实现跳转的话,那么代码就是:

<?php

if(......){// session is invalid
 
    $url = 'login.php';
    header('location:'.$url);
}

?>

在使用过程之中,我发现这样子跳转之后重新加载的login.php页面只会出现在id="mainframe"的frame中,看截图:

后台页面布局如下:

<frameset rows="70,*" cols="*" frameborder="no" border="0" framespacing="0">

  <frame src="index.php?action_type=top" name="topframe" scrolling="no" noresize="noresize" id="topframe" title="" />

  <frameset cols="225,*" frameborder="no" border="0" framespacing="0">

    <frame src="index.php?action_type=menu" name="menuframe" scrolling="no" noresize="noresize" id="menuframe" title="" />

    <frame class="framebordertop" src="index.php?action_type=login-info" name="mainframe" scrolling="auto" noresize="noresize" id="mainframe" title="" />

  </frameset>

</frameset>

<noframes>
<body>
</body>
</noframes>

 

我应该去查一查php manual中关于header('location:...')的用法,http://hk2.php.net/manual/zh/function.header.php。

后来我使用了stackoverflow别人给的代码来解决这个问题:

<?php

if($_SESSION['admin_id']==''){

  //header('Location:login.php');
  die("<script>
    if(typeof(parent) != 'undefined'){
        parent.window.location = 'login.php';
    }else{
        window.location.href = 'login.php';
    }
  </script>");
}
?>

 

posted on 2014-09-01 19:04  smelikecat  阅读(630)  评论(0编辑  收藏  举报