一、用户个人信息模块设计

1.用户个人信息模块概述
    用户登录后,即可看到个人的相关信息。在这里,用户可以查看个人用户名称、权限等级、当前日期,上次登录时间、登录次数并可执行安全退出操作。

2.用户个人信息模块技术
    在个人信息显示模块中,以SESSION变量中存储的用户ID为条件,从用户信息表中查询出用户信息,并且将该用户信息在该页面中输出。
    userinfo.php关键代码如下:
<?php
    header("Content-Type:text/html;charset=utf-8");
    date_default_timezone_set('PRC');           // 设置为北京时间

    session_start();                            // 初始化SESSION变量
    include_once("conn/conn.php");              // 包含配置文件   

    // echo "用户id = " . $_SESSION['id'];  

    // 查找用户资料
    // 执行查询操作
    $sqlstrvi = "select * from tb_meeting_user where userId = $_SESSION[id]";

    $testrst = mysql_query($sqlstrvi);
    // 从结果集中取得一行作为关联数组
    $testrst = mysql_fetch_array($testrst,MYSQL_ASSOC);

     print_r($testrst);
?>

<table cellpadding="0" cellspacing="0" border="0">
    <tr>
        <td width="58" align="center">尊敬的:</td>
        <td width="48" align="left"><?php echo $testrst['userName']?></td>
        <td width="68">您的身份:</td>
        <td width="78" align="left">
            <?php
                // 判断用户权限
                if($testrst['userRights'] == 0){            // 普通用户
                    echo "<span style=\"color:#c9f\">普通用户</span>";
                }else if($testrst['userRights'] == 1){      // 管理员
                    echo "<span style=\"color:#f00\">管理员</span>";
                }
            ?>
        </td>
        <td>
            当前日期为:
            <span class="dates">
                <?php echo date("Y年m月d日");?>
            </span>&nbsp;
        </td>
        <td width="78">上次登录时间:</td>
        <td width="138">
            <?php
                if($testrst['userLoginCount'] == 1){           // 判断用户是否为首次登录
                    echo "------";
                }else{
                    echo $_SESSION["lasttime"];
                }
            ?>
        </td>
        <td width="40">当前为:</td>
        <td width="100" align="left">
            第&nbsp;<?php echo $testrst['userLoginCount'];?>&nbsp;次登录
        </td>
        <!--<td width="51"><a href="logout.php">退出登录</a></td>-->
        <td width="51">
            <a href="logout.php" onclick="return logout();">
                <img src="images/over3.png" width="49" height="19" border="0" onclick="logout()" alt="安全退出" />
            </a>
        </td>
    </tr>
</table>

<script>
    // 安全退出
    function logout(){
        if(confirm("确定要退出登录吗?")){
            // 如果用户确认退出,则打开logout.php页
            window.open('logout.php','_parent','',false);
        }else{
            retrurn false;
        }
    }
</script>

这里值得一提的是,该模块输出的上次登录时间,并非直接通过查询数据库中相关字段的内容获取而来,而从SESSION变量存储的lasttiame中获得的。

logout.php关键代码如下:

<?php
    header("Content-Type:text/html;charset=utf-8");
    date_default_timezone_set('PRC');           // 设置为北京时间

    session_start();            // 开启SESSION支持
    session_destroy();          // 销毁SESSION
    // 回到首页
    echo '<script>alert(\'用户已安全退出!\');location=(\'index.php\');</script>';
?>
Logo

快速构建 Web 应用程序

更多推荐