Home index.php
<?phpheader (' content-type:text/html;charset=utf-8 ');/* * * mail System Instance * */ require ' conn.inc.php ';//Load Connection database configuration //If you are not logged in go to the login page if (! Isset ($_session[' islogin ') && $_session[' IsLogin ']===1)) { header ("Location:login.php"); } echo "Hello:". $_session[' username ']. " <a href= ' logout.php ' > Exit </a> "; if ($_session[' allow_1 '] ==1 ) { echo ' You have 1 this permission! <br/> '; } &nbsP; if ($_session[' allow_2 '] ==1 ) { echo ' You have 2 this permission! <br/> '; } if ($_session[' allow_3 '] ==1 ) { echo ' You have 2 this permission! <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 "You have". $stmt->rowcount (). " Email <br/> "; echo ' <table border=" 1 " width=" 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 Page login.php
<?php //Processing Login if (isset ($_post[' dosubmit ')) { include ' conn.inc.php '; //to the database to find the correct user input $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) { //putting user information in session at once $_session= $stmt->fetch (PDO::FETCH_ASSOC); //Plus login tag $_session[' IsLogin ' ] = 1; header ("Location:index.php"); }}?>Database connection configuration file conn.inc.php
<?php include ' config.php '; try{$pdo = new PDO (DSN, DBUSER,DBPWD); }catch (pdoexception $e) {echo "Database connection failed:". $e->getmessage (); Exit }
Configuration file 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 ();//Open session
Database Design User Table
create table user ( id int (one) not null primary key auto_ Increment, username varchar ( not null, password char) ( not null, email varchar (+) 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);
Database design Email table
create table email ( id int not null auto_increment , Uid int not null default 0, title varchar ( 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 ');
This article is from the "Jin Sha Harbor" blog, please be sure to keep this source http://11410485.blog.51cto.com/11400485/1843070
PHP SESSION Application mail System Instance Gaulo