PHP SESSION Application mail System Instance Gaulo

Source: Internet
Author: User
Tags dsn php session rowcount

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.