fordev22.com
  • Home
  • สอนทำระบบ POS (Point of Sale)
  • Flutter สำหรับผู้เริ่มต้น
  • PHP+MySqli
  • เนื้อหาอื่น ๆ
    • สอน Bootstrap 5
    • Dreamweaver+Bootstrap+PHP
    • Dreamweaver
    • Computer Tip
  • ABOUT US
    • Personal information
    • บริการ
    • ผลงาน
    • ตัวอย่าง ผลงานด้านการสอน (สอนสดผ่าน Google Meet, Zoom)
  • Search

PHP+MySqli EP.6 Login Logout แบบแยกสิทธ์การใช้งาน

March 4, 2019/in PHP+MySqli /by fordev22

PHP+MySqli EP.6 Login Logout แบบแยกสิทธ์การใช้งาน
ในขั้นตอนการทำไม่ยากอย่างที่คิดแค่ทำตามวีดีโอและมีโค๊ดสำเร็จรูป
ให้เรียบร้อยแล้ว

 

 

 

 

 


    SQL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
-- phpMyAdmin SQL Dump
-- version 4.7.0
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Generation Time: Aug 17, 2018 at 07:08 PM
-- Server version: 10.1.25-MariaDB
-- PHP Version: 5.6.31
 
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
 
 
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
 
--
-- Database: `porjecticecream`
--
 
-- --------------------------------------------------------
 
--
-- Table structure for table `tbl_member`
--
 
CREATE TABLE `tbl_member` (
  `member_id` int(11) NOT NULL COMMENT 'ลำดับ',
  `member_firstname` varchar(50) NOT NULL COMMENT 'ชื่อ',
  `member_lastname` varchar(50) NOT NULL COMMENT 'นามสกุล',
  `member_username` varchar(50) NOT NULL COMMENT 'ชื่อผู้ใช้',
  `member_password` varchar(50) NOT NULL COMMENT 'รหัสผ่าน',
  `member_img` varchar(200) DEFAULT NULL COMMENT 'รูปผู้ใช้',
  `member_phone` varchar(20) NOT NULL COMMENT 'เบอร์โทร',
  `member_address` text NOT NULL COMMENT 'ที่อยู่',
  `member_email` varchar(50) NOT NULL COMMENT 'อีเมล',
  `member_level` varchar(10) NOT NULL COMMENT 'ระดับการใช้งาน',
  `daetinsert` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'วันที่เพิ่มข้อมูล'
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
--
-- Dumping data for table `tbl_member`
--
 
INSERT INTO `tbl_member` (`member_id`, `member_firstname`, `member_lastname`, `member_username`, `member_password`, `member_img`, `member_phone`, `member_address`, `member_email`, `member_level`, `daetinsert`) VALUES
(1, 'คมกริช', 'khomkrit', 'khomkrit', 'khomkrit', 'mempic/15773_714537791953661_4700613261033821328_n.jpg', '0901542966', '199\\68 พีโน่ ปิ่นเกล้าราชพฤก', 'fordza4you@hotmail.com', 'a', '2015-02-23 13:36:20'),
(3, 'fff', 'fff', '1234', '1234', 'mempic/SmartWMS.jpg', '0355558989', 'xcxc', 'xcxc', 'm', '2015-02-26 13:21:57'),
(4, 'นายเข้มข้น', 'แข็งแรง', '1111', '1111', 'mempic/Security.ico', '022225566', 'dfgdf', 'gdfgdf', 'm', '2015-02-26 13:28:34'),
(8, 'นางสาวสวยงาม', 'น่ารักจัง', '6666', '6666', 'mempic/Secretary.ico', '0899959784', 'dfsgsdg', 'ooo@kkk', 'm', '2015-03-13 18:24:59'),
(9, 'นายราเชน', 'สีสวยงาม', '000', '000', 'mempic/King.ico', '0816522235', 'hgkjgj', 'klsdklsdklsdf@klfgklh', 'm', '2015-03-14 14:06:48'),
(10, 'นายรักดี', 'รักชาติ', '4087', '4087', 'mempic/Client.ico', '0988858589', '199/68 บางขนุน จ.นนทบุรี 11130', 'fast7@hotmail.com', 'm', '2015-06-10 18:06:28'),
(11, 'นาย เรียนดี', 'ตั้งใจเรียน', 'computer', 'computer', 'mempic/Uncle Sam.ico', '0988858585', ' 199/68 พลีโน่ ปิ่นเกล้า-ราชพฤก บางกรวย จ.นนทบุรี 11130', 'computer@gmail.com', 'm', '2015-07-27 16:35:02'),
(13, '1', '1', '1', '1', 'mempic/user-male-circle.png', '1', ' 1', 'fordza4you@gmail.com', 'a', '2018-07-23 10:59:38'),
(14, '2', '2', '2', '2', 'mempic/circled_user_female1600.png', '2', ' 2', 'fordza4you@hotmail.com', 'm', '2018-07-23 11:00:27'),
(15, 'g', 'g', 'g', 'g', 'mempic/user-male-circle.png', '4', ' g', 'gg@gmail.com', 'm', '2018-07-23 15:58:49');
 
--
-- Indexes for dumped tables
--
 
--
-- Indexes for table `tbl_member`
--
ALTER TABLE `tbl_member`
  ADD PRIMARY KEY (`member_id`);
 
--
-- AUTO_INCREMENT for dumped tables
--
 
--
-- AUTO_INCREMENT for table `tbl_member`
--
ALTER TABLE `tbl_member`
  MODIFY `member_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ลำดับ', AUTO_INCREMENT=16;COMMIT;
 
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
 

  1. สร้างไฟล์ connect ในที่นี้ชื่อว่า c_log.php
    1
    2
    3
    4
    <?php
    $con= mysqli_connect("localhost","root","","ใส่ชื่อ Database") or die("Error: " . mysqli_error($con));
    mysqli_query($con, "SET NAMES 'utf8' ");
    ?>
  2. ออกแบบหน้าฟอร์มพร้อมตั้งชื่อ textfield ในหน้านี้ให้ชื่อว่า c_form.php
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    <?php session_start();?>
    <!doctype html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Form Login</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    </head>
    <body>
     
          <form name="frmlogin"  method="post" action="c_login.php">
            <p> </p>
            <p><b> Login Form </b></p>
            <p> ชื่อผู้ใช้ :
              <input type="text"   id="Username" required name="Username" placeholder="Username">
            </p>
            <p>รหัสผ่าน :
              <input type="password"   id="Password"required name="Password" placeholder="Password">
            </p>
            <p>
              <button type="submit">Login</button>
              &nbsp;&nbsp;
              <button type="reset">Reset</button>
              <br>
            </p>
          </form>
    </body>
    </html>
  3. หน้าเช็คเวลาเข้าloginและแยกสิทธ์ในที่ให้ชื่อว่า c_login.php
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    <?php
    echo "<pre>";
    print_r($_POST);
    echo "</pre>";
    session_start();
            if(isset($_REQUEST['Username'])){
    //connection
                      include("Connections/c_log.php");
    //รับค่า user & password
                      $Username = $_REQUEST['Username'];
                      $Password = $_REQUEST['Password'];
    //query
                      $sql="SELECT * FROM tbl_member Where member_username='".$Username."' and member_password='".$Password."' ";
     
                      $result = mysqli_query($con,$sql);
                      if(mysqli_num_rows($result)==1){
     
                          $row = mysqli_fetch_array($result);
     
                          $_SESSION["UserID"] = $row["member_id"];//ประกาศตัวแปรUserIDไว้เพื่อส่งค่า
                          $_SESSION["User"] = $row["member_firstname"]." ".$row["member_lastname"];//ประกาศตัวแปรUserไว้เพื่อส่งค่า
                          $_SESSION["Userlevel"] = $row["member_level"];//ประกาศตัวแปรUserlevelไว้เพื่อส่งค่า
     
                          if($_SESSION["Userlevel"]=="a"){ //ถ้าเป็น admin ให้กระโดดไปหน้า admin_page.php
     
                            Header("Location: admin_page.php");
     
                          }
     
                          if ($_SESSION["Userlevel"]=="m"){  //ถ้าเป็น member ให้กระโดดไปหน้า user_page.php
     
                            Header("Location: user_page.php");
     
                          }
     
                      }else{
                        echo "<script>";
                            echo "alert(\" user หรือ  password ไม่ถูกต้อง\");";
                            echo "window.history.back()";
                        echo "</script>";
     
                      }
     
            }else{
     
     
                 Header("Location: c_form.php"); //user & password incorrect back to login again
     
            }
    ?>
  4. หน้าผู้เข้าใช้user แสดงข้อมูลผู้ใช้ ในที่นี้ให้ชื่อว่า user_page.php
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    <?php session_start();?>
    <?php
     
    if (!$_SESSION["UserID"]){
     
      Header("Location: c_form.php");
     
    }else{?>
    <!doctype html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>User page</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    </head>
    <body>
     
        <h1>You are Member</h1>
        <p><strong>hi </strong>:
        <?php echo ($_SESSION['User']);?> <!--show detail login-->
          <?php //session_destroy();?>
        </p>
        <p><strong>
        <a href="c_logout.php">Log out</a></strong></p>
     
    </body>
    </html>
    <?php }?>
  5. หน้าผู้เข้าใช้admin แสดงข้อมูลผู้ใช้ ในที่นี้ให้ชื่อว่า admin_page.php
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    <?php session_start();?>
    <?php
     
    if (!$_SESSION["UserID"]){  //check session
     
      Header("Location: c_form.php"); //ไม่พบผู้ใช้กระโดดกลับไปหน้า login form
     
    }else{?>
    <!doctype html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Admin page</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    </head>
    <body>
        <h1>You are Administrator </h1>
        <p><strong>hi</strong> :&nbsp;<?php echo ($_SESSION['User']);?> <!--show detail login-->
          <?php //session_destroy();?>
        </p>
        <p>&nbsp;</p>
        <p><a href="c_logout.php">Log out</strong></a></p>
        <p>&nbsp;</p>
     
    </body>
    </html>
    <?php }?>
  6. หน้า logout ออกจากระบบ ในที่นี้ให้ชื่อว่า c_logout.php
    1
    2
    3
    4
    5
    <?php
    session_start();
    session_destroy();
    header("Location: c_form.php ");
    ?>
     

Facebook
Twitter
Line
Tags: Database, Edit Sqli, login, Login Logout Sqli, Login Sqli, php, showe Sqli, sqli, Sqli Login
Share this entry
  • Share on Facebook
  • Share on Twitter
  • Share on Google+
  • Share on Pinterest
  • Share on Linkedin
  • Share on Tumblr
  • Share on Vk
  • Share on Reddit
  • Share by Mail
https://fordev22.com/wp-content/uploads/2018/10/phpsqli.png 720 970 fordev22 https://fordev22.com/wp-content/uploads/2018/08/logo_fordev22_2.png fordev222019-03-04 23:21:262019-03-05 00:03:25PHP+MySqli EP.6 Login Logout แบบแยกสิทธ์การใช้งาน
You might also like
PHP+MySqli EP.38 PHP Selecting and Using Multiple MySqli Database
PHP+MySqli EP.7 แบ่งหน้าการแสดงข้อมูลออกเป็นหน้าๆ (Simple Pagination)
PHP+MySqli EP.25 Preview an image before it is uploaded (การแสดงรูปภาพก่อน บันทึกเข้า Database)
PHP+MySqli EP.15 PHP Condition & SWEET ALERT (การใช้งาน SWEET ALERT ร่วมกับ PHP)
สอนทำระบบ POS (ระบบขายหน้าร้าน) Ep 33. Update ข้อมูลสินค้า หลังจากตัดสต๊อก (บันทึกการสั่งซื้อ Part 5)
(2023) PHP+MySqli EP.41 How to AJAX CrudPHP MySqli (Part 1 insert AND view)
PHP+MySqli EP.20 Data Table Order (การเรียงลำดับ Data Table)
PHP+MySqli EP.22 การกำหนดการแสดงของวันที่แบบสากล (php function Dateformat)

บริการและผลงาน

  • Home
  • Personal Information
  • คอสเรียนที่เปิดอยู่
  • ตัวอย่าง ผลงานด้านการสอน (สอนสดผ่าน Google Meet, Zoom)
  • บริการ
  • ผลงาน

ช่องทางการติดต่อ

Tel. 090-959-1107

ID Line. fordza4you

E-mail. fordza4you@gmail.com


รับพัฒนาระบบ
รับพัฒนาเว็บแอพพลิเคชั่น
รับพัฒนาเว็บไซต์

Page

Popular
  • สอน Flutter Ep 4. ติดตั้ง SDK Simulator...June 7, 2023 - 1:54 pm
  • Computer Tip EP.2 การปรับเสียง...October 13, 2016 - 10:13 pm
  • Dreamweaver EP.1 ลงโปรแกรมจำลอง...October 15, 2016 - 9:28 pm
  • Dreamweaver EP.2 สร้าง Database ด้วย ...October 16, 2016 - 12:48 pm
  • Dreamweaver EP.3 การสร้างที่เก็บเว็บไซต์และสร้าง...October 16, 2016 - 6:33 pm
Recent
  • สอน Flutter Ep 4. ติดตั้ง SDK Simulator...June 7, 2023 - 1:54 pm
  • สอน Flutter Ep 3. ติดตั้ง Xcode เพื่อใช้...June 7, 2023 - 1:49 pm
  • สอน Flutter Ep 2. วิธีติดตั้ง...June 7, 2023 - 1:16 pm
  • สอน Flutter Ep 1. วิธีติดตั้ง...June 7, 2023 - 10:52 am
  • (2023) PHP+MySqli EP.43 How to AJAX CrudPHP MySqli (Part...April 21, 2023 - 6:15 pm
Comments
  • sssssMay 4, 2017 - 11:52 am by fordev22
  • sssssMay 4, 2017 - 11:50 am by fordev22
  • Awaiting BACS payment Order status changed from Pending...March 1, 2017 - 9:23 am by WooCommerce
Tags
Bootstrap Database Datatable Datatable Serverside Dreamweaver Edit Sqli Mysqli php php+sqli php+sqli php+sqli Point of Sale Point of SalePOS POS POS System POS System showe Sqli sqli xampp กับ dreamweaver ฟรีโปรเจคนักศึกษา ฟอร์ม php รับพัฒนาระบบ รับพัฒนาระบบ รับเขียนโปรแกรม รับเขียนโปรแกรม ลบข้อมูล สร้าง Database สอน bootstrap สอน php สอน php mysql สอน php mysqli สอน php พื้นฐาน สอน php เบื้องต้น สอนทำเว็บ สอนทำเว็บ สอนทำเว็บ สอนพัฒนาระบบ สอนพัฒนาระบบ สอนเขียนเว็บ สอนเขียนเว็บ สอนเขียนเว็บ สอนเขียนโปรแกรม สอนเขียนโปรแกรม เขียนโปรแกรมราคาถูก เขียนโปรแกรมราคาถูก เพิ่มข้อมูล เพิ่มรูป แจกระบบ php แจกโคด php โปรเจคคอมธุ โปรเจคคอมพิวเตอร์ โปรเจคคอมพิวเตอร์ธุรกิจ โปรเจคจบ คอมพิวเตอร์ โปรเจคนักศึกษา โปรเจควิทยาการคอม โปรเจควิทยาการคอม Share this entry

Copyright@2018.fordev22.com

PHP+MySqli EP.5 การเพิ่มข้อมูลเข้า Database... PHP+MySqli EP.7 แบ่งหน้าการแสดงข้อมูลออกเป็นหน้าๆ...
Scroll to top