Tennessee3Waltz 发表于 2014-03-18 20:30

【已解决】新手请教达人html页面如何用加session验证

本帖最后由 Tennessee3Waltz 于 2014-03-18 20:51 编辑

hi,
我搜了各种中英文帖子,实在没找到解决办法,只能来此求助大神解答了。我的html页面由三个frame组成(据说这是种很过时的技术:( )。这个html需要做个session鉴权,如果是已登录用户,则展示该html页面;如果不是,则跳转到login界面。另外,其中一个frame里我需要读session以便显示"您好,$username"的信息。我发现我总是做不到当用户未登录时,让用户跳转至login的功能。以下是我的代码:
html页面:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/frameset.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>管理员</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<META content="MSHTML 6.00.2900.3492" name=GENERATOR></HEAD><FRAMESET
frameSpacing=0 rows=80,* frameBorder=0><FRAME name=top
src="index/YHTop.php" frameBorder=0 noResize
scrolling=no><FRAMESET frameSpacing=0 frameBorder=0 cols=220,*><FRAME name=menu
src="index/YHMenu.php" frameBorder=0 noResize><FRAME name=dmMain
src="index/Admin_main.php"
frameBorder=0></FRAMESET><NOFRAMES>
      <p>This page requires frames, but your browser does not support them.</p>
    </NOFRAMES></FRAMESET></HTML>
<?php
    session_start();
    if(!isset($_SESSION['login_user']))
    {
                session_destroy();
                echo "<script> {window.alert('您未登录,请先登录');location.href='../login/login.php'} </script>";
    }?>显示“您好,$username”的YHTop.php部分代码:<html>
...
<TD height=35 align="right"><A
            target=_top><B><?php session_start();echo $_SESSION['login_user']?>:&nbsp;</B></FONT></A></TD>
...
</html>坐等CU大神回复~

Tennessee3Waltz 发表于 2014-03-18 20:50

html 页面改成下面的就可以了,汗:
<?php
    session_start();
    if(!isset($_SESSION['login_user']))
    {
                session_destroy();
                echo "<script> {window.alert('您未登录,请先登录');location.href='../login/login.php'} </script>";
    }?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/frameset.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>管理员</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<META content="MSHTML 6.00.2900.3492" name=GENERATOR></HEAD><FRAMESET
frameSpacing=0 rows=80,* frameBorder=0><FRAME name=top
src="index/YHTop.php" frameBorder=0 noResize
scrolling=no><FRAMESET frameSpacing=0 frameBorder=0 cols=220,*><FRAME name=menu
src="index/YHMenu.php" frameBorder=0 noResize><FRAME name=dmMain
src="index/Admin_main.php"
frameBorder=0></FRAMESET><NOFRAMES>
      <p>This page requires frames, but your browser does not support them.</p>
    </NOFRAMES></FRAMESET></HTML>
页: [1]
查看完整版本: 【已解决】新手请教达人html页面如何用加session验证