您的位置:首页 > 编程语言 > PHP开发

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

2014-09-01 19:04 302 查看
一般,我们的管理后台都是使用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>");
}
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: