PHP SESSION 應用 郵件系統執行個體 高洛峰 細說PHP

來源:互聯網
上載者:User

標籤:php session 應用 郵件系統執行個體 高洛峰 細說php

首頁 index.php

<?phpheader(‘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 ><h1>郵件登入系統</h1><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‘,‘[email protected]‘,0,0,0); insert into user(username,password,email,allow_1,allow_2,allow_3) values(‘xiaowang2‘,‘1234‘,‘[email protected]‘,0,0,0); insert into user(username,password,email,allow_1,allow_2,allow_3) values(‘xiaowang3‘,‘1234‘,‘[email protected]‘,0,0,0);  insert into user(username,password,email,allow_1,allow_2,allow_3) values(‘xiaowang4‘,‘1234‘,‘[email protected]‘,0,0,0); insert into user(username,password,email,allow_1,allow_2,allow_3) values(‘xiaowang5‘,‘1234‘,‘[email protected]‘,0,0,0); insert into user(username,password,email,allow_1,allow_2,allow_3) values(‘xiaowang6‘,‘1234‘,‘[email protected]‘,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‘);


本文出自 “津沙港灣” 部落格,請務必保留此出處http://11410485.blog.51cto.com/11400485/1843070

PHP SESSION 應用 郵件系統執行個體 高洛峰 細說PHP

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.