session login แล้วนำชื่อ Login มาแสดง

ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา session login แล้วนำชื่อ Login มาแสดง

session login แล้วนำชื่อ Login มาแสดง
อยากจะแสดงชื่อของผู้ login จาก session ครับ ต้องเขียนโค้ดยังไงครับ
Database
Table > staff
-staff_id
-staff_fname
-staff_lname
-staff_name
-staff_password

<?php
  include 'dbcon.php';
  session_start();
if($_SERVER["REQUEST_METHOD"] == "POST")
 {
// username and password received from loginform 
$staff_name=mysqli_real_escape_string($conn,$_POST['staff_name']);
$staff_password=mysqli_real_escape_string($conn,$_POST['staff_password']);

$sql_query="SELECT staff_id FROM staff WHERE staff_name='$staff_name' and staff_password='$staff_password'";
$result=mysqli_query($conn,$sql_query);
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
$count=mysqli_num_rows($result);


// If result matched $username and $password, table row must be 1 row
if($count==1)
{
$_SESSION["session_id"] = session_id();
$_SESSION['staff_name']= $staff_name;

header("location: home.php");
}
else
{

  $error = "ชื่อผู้ใช้ หรือ รหัสผ่านไม่ถูกต้อง!";
}
}
?>

<!DOCTYPE html>
<html lang="th">
	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8">
		<meta charset="utf-8">
		<title>ระบบสินค้าคงคลัง</title>
		<meta name="generator" content="Bootply" />
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link href="css/loginbootstrap.min.css" rel="stylesheet">
		<!--[if lt IE 9]>
			<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
		<![endif]-->
		<link href="css/login.css" rel="stylesheet">
	</head>
	<body>
<!--login modal-->
<div id="loginModal" class="modal show" tabindex="-1" role="dialog" aria-hidden="true">
  <div class="modal-dialog">
  <div class="modal-content">
      <div class="modal-header">
          
          <h1 class="text-center" style="color: #337AB7"><i class="glyphicon glyphicon-shopping-cart"></i> ระบบสินค้าคงคลัง</h1>
      </div>
      <?php
      if(isset($error))
      {
           ?>
                     <div class="alert alert-danger">
                        <i class="glyphicon glyphicon-warning-sign"></i> &nbsp; <?php echo $error; ?> !
                     </div>
                     <?php
      }
      ?>
      <div class="modal-body">
          <form class="form col-md-12 center-block" method="post" action="">
            <div class="form-group">
              <input type="text" class="form-control input-lg" placeholder="ชื่อผู้ใช้ | username" name="staff_name" id="staff_name">
            </div>
            <div class="form-group">
              <input type="password" class="form-control input-lg" placeholder="รหัสผ่าน | password" name="staff_password" id="staff_password">
            </div>
            <div class="form-group" >
              <button class="btn btn-primary btn-lg btn-block" type="submit" >เข้าสู่ระบบ  <i class="glyphicon glyphicon-log-in"></i> </button>
            </div>

          </form>
      </div>
      <div class="modal-footer">
          <div class="col-md-12">

		  </div>	
      </div>
  </div>
  </div>
</div>
	<!-- script references -->
		<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
		<script src="js/loginbootstrap.min.js"></script>
	</body>
</html>
อยากให้ชื่อผู้เข้าใช้มาแสดง


โดยการเข้าระบบด้วย  staff_name / staff_password
แล้วนำเอาชื่อ staff_fname มาแสดงครับ


Oliviernewt 171.6.186.xxx 29-11-2016 16:31:49

คำแนะนำ และการใช้งาน

สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก


  • ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
  • เปลี่ยน


    ( หรือ เข้าใช้งานผ่าน Social Login )

 ความคิดเห็นที่ 1
ดูเนื้อหานี้เป็นแนวทาง

แนวทางห้ามบัญชีผู้ใช้ ไม่ให้ล็อกอินใช้งานพร้อมกัน ด้วย php และ ajax 


ninenik 183.88.39.xxx 29-11-2016






เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ