您好,登录后才能下订单哦!
密码登录
            
            
            
            
        登录注册
            
            
            
        点击 登录注册 即表示同意《亿速云用户服务条款》
        首页 index.php
<?php
header('content-type:text/html;charset=utf-8');
/*
 * 
 * 邮件系统实例
 * 
 */
        require 'conn.inc.php';//加载连接数据库配置
        //如果没有登录 就去登录页面
        if(!(isset($_SESSION['islogin']) && $_SESSION['islogin']===1)){
            header("Location:login.php");
        }
        echo "你好:".$_SESSION['username']."<a href='logout.php'>退出</a>";
        
        if($_SESSION['allow_1'] ==1 ){
            echo '你有1这个权限!<br/>';
        }
        
        if($_SESSION['allow_2'] ==1 ){
            echo '你有2这个权限!<br/>';
        }
        
        if($_SESSION['allow_3'] ==1 ){
            echo '你有2这个权限!<br/>';
        }
            $query = "select id,uid,title,ptime,mbody from email where uid=?";
            $stmt = $pdo->prepare($query);
            $stmt->execute(array($_SESSION['id']));
         
            $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
         echo "你有".$stmt->rowCount()."封邮件<br/>"; 
         echo '<table border="1" width="800" align="center">';
         foreach ($data as $value){
             echo '<tr align="center">';
             echo '<td>'.$value['id'].'</td>';
             echo '<td>'.$value['title'].'</td>';
             echo '<td>'.$value['ptime'].'</td>';
             echo '<td>'.$value['mbody'].'</td>';
             echo '</tr>';
         }
         echo '</table>';登录页面login.php
<?php 
//处理登录
if(isset($_POST['dosubmit'])){
    include 'conn.inc.php';
    //到数据库查找用户输入的是否正确
    $query = "select id, username, allow_1,allow_2,allow_3 from user where username = ? and password =?";
    $stmt = $pdo->prepare($query);
    $stmt ->execute(array($_POST['username'],$_POST['password']));
    if($stmt->rowCount()>0){
        //将用户信息一次性放到session中
        $_SESSION=$stmt->fetch(PDO::FETCH_ASSOC);
        
        //加登录标记
        $_SESSION['islogin'] = 1;
        header("Location:index.php");
    }
}
?>
<html>
<head>
<title>PHP study</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<script type="text/javascript" >
<!--
//-->
</script>
</head>
<body >
<h2>邮件登录系统</h2>
<form action="login.php" method="post">
用户名:<input type="text" name="username" /><br />
密码:<input type="password" name="password" /><br />
<input type="submit" name="dosubmit" value="登录邮件" />
</form>
</body>
</html>数据库连接配置文件conn.inc.php
<?php
        include 'config.php';
        try{
            $pdo = new PDO(DSN, DBUSER,DBPWD);        
        }catch(PDOException $e){
            echo "数据库连接失败:".$e->getMessage();
            exit;
        }配置文件config.php
<?php const DSN = 'mysql:host=localhost;dbname=test'; const DBUSER = 'root'; const DBPWD = 'root'; header('content-type:text/html;charset=utf-8'); session_start();//开启会话
数据库设计 user表
 create table user(
 id int(11) not null primary key auto_increment,
 username varchar(50) not null,
 password     char(32) not null,
 email varchar(80) not null,
 allow_1 smallint(6) not null default 0,
 allow_2 smallint(6) not null default 0,
 allow_3 smallint(6) not null default 0
 );
 
 insert into user(username,password,email,allow_1,allow_2,allow_3) values('xiaowang1','1234','xiaowang@163.com',0,0,0);
 insert into user(username,password,email,allow_1,allow_2,allow_3) values('xiaowang2','1234','xiaowang@163.com',0,0,0);
 insert into user(username,password,email,allow_1,allow_2,allow_3) values('xiaowang3','1234','xiaowang@163.com',0,0,0); 
 insert into user(username,password,email,allow_1,allow_2,allow_3) values('xiaowang4','1234','xiaowang@163.com',0,0,0);
 insert into user(username,password,email,allow_1,allow_2,allow_3) values('xiaowang5','1234','xiaowang@163.com',0,0,0);
 insert into user(username,password,email,allow_1,allow_2,allow_3) values('xiaowang6','1234','xiaowang@163.com',0,0,0);数据库设计 email表
create table email( id int not null auto_increment , uid int not null default 0, title varchar(80) not null default ' ', ptime int not null default 0, mbody text, primary key(id) ); insert into email(uid,title,ptime,mbody) values(1,'wo',1222333,'I am a boy'); insert into email(uid,title,ptime,mbody) values(1,'wos',1222333,'I am a boy'); insert into email(uid,title,ptime,mbody) values(1,'wo1',1222333,'I am a boy'); insert into email(uid,title,ptime,mbody) values(1,'wo2',1222333,'I am a boy'); insert into email(uid,title,ptime,mbody) values(2,'2wo',1222333,'I am a boy'); insert into email(uid,title,ptime,mbody) values(2,'2wos',1222333,'I am a boy'); insert into email(uid,title,ptime,mbody) values(2,'2wo1',1222333,'I am a boy'); insert into email(uid,title,ptime,mbody) values(2,'2wo2',1222333,'I am a boy'); insert into email(uid,title,ptime,mbody) values(3,'3wo',1222333,'I am a boy'); insert into email(uid,title,ptime,mbody) values(3,'3wos',1222333,'I am a boy'); insert into email(uid,title,ptime,mbody) values(3,'3wo1',1222333,'I am a boy'); insert into email(uid,title,ptime,mbody) values(3,'3wo2',1222333,'I am a boy');
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。