Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > สอบถาม php ครับ เวลาล็อคอินผ่านหน้า log in ไปแล้วเข้าหน้าหลัก ถ้าไม่ให้เข้าหน้าหลักโดยตรงต้องทำยังงัย



 

สอบถาม php ครับ เวลาล็อคอินผ่านหน้า log in ไปแล้วเข้าหน้าหลัก ถ้าไม่ให้เข้าหน้าหลักโดยตรงต้องทำยังงัย

 



Topic : 121583



โพสกระทู้ ( 5 )
บทความ ( 0 )



สถานะออฟไลน์




พอดีผมสั่งหน้า login ให้ authen user และ password จาก AD จากเซิฟเวอร์ได้แล้ว ถ้า login ผ่าน จะเข้าหน้าชื่อว่า main_menu.php
ได้แล้ว แต่ปัญหาของผมคือคนที่รู้หน้าหลักว่าชื่อ main_menu.php สามารถเรียกเข้าได้โดยตรงไม่ต้องผ่านหน้า login ผมสามารถทำให้เวลาเค้าเรียกหน้า main_menu.php แล้วเด้งไปหน้า login ก่อนได้มั้ยครับมีวิธีไหนบ้างครับมือใหม่



Code หน้า index.php

Code (PHP)
<?php
if(isset($_POST['username']) && isset($_POST['password'])){

    $adServer = "192.168.1.1";
	
    $ldap = ldap_connect($adServer);
    $username = $_POST['username'];
    $password = $_POST['password'];

    $ldaprdn = 'lightsource' . "\\" . $username;

    ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
    ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);

    $bind = @ldap_bind($ldap, $ldaprdn, $password);


    if ($bind) {
        $filter="(sAMAccountName=$username)";
        $result = ldap_search($ldap,"DC=ตัวอย่าง,DC=co,DC=th",$filter);
        ldap_sort($ldap,$result,"sn");
        $info = ldap_get_entries($ldap, $result);
        for ($i=0; $i<$info["count"]; $i++)
        {
           
            
         
	echo "<meta http-equiv='refresh' content='0 ;url=main_menu.php'>" ;

	  
	  
             
        }
        @ldap_close($ldap);
    } else {
        $msg = "Invalid email address / password";
        echo $msg;
    }

}else{
?>
<form action="#" method="POST">

    
<?php } ?> 




<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>:: Home</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">

<!-- Le styles -->
<link href="assets/css/bootstrap.css" rel="stylesheet">
<style type="text/css">
/* Sticky footer styles
      -------------------------------------------------- */

      html, body {
	height: 100%;/* The html and body elements cannot have any padding or margin. */
}
/* Wrapper for page content to push down footer */
      #wrap {
	min-height: 100%;
	height: auto !important;
	height: 100%;
	/* Negative indent footer by it's height */
        margin: 0 auto -60px;
}
/* Set the fixed height of the footer here */
      #push, #footer {
	height: 60px;
}
#footer {
	background-color: #f5f5f5;
}

      /* Lastly, apply responsive CSS fixes as necessary */
      @media (max-width: 767px) {
 #footer {
 margin-left: -20px;
 margin-right: -20px;
 padding-left: 20px;
 padding-right: 20px;
}
}
/* Custom page CSS
      -------------------------------------------------- */
      /* Not required for template or sticky footer method. */

      #wrap > .container {
	padding-top: 60px;
}
.container .credit {
	margin: 20px 0;
}
code {
	font-size: 80%;
}
</style>
<link href="assets/css/bootstrap-responsive.css" rel="stylesheet">

<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
      <script src="../assets/js/html5shiv.js"></script>
    <![endif]-->

<!-- Fav and touch icons -->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="assets/ico/apple-touch-icon-57-precomposed.png">
<link rel="shortcut icon" href="assets/ico/favicon.png">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<body background="admin/images/1180422460.gif">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><br>
</p>
<table width="100%" border="0">
  <tr>
    <td align="center">&nbsp;</td>
  </tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<form ACTION="<?php echo $loginFormAction; ?>" name="login" method="POST">
  <table width="35%" border="0" align="center">
    <tr>
      <td height="27"><strong><i class="icon-user"></i>&nbsp;Username&nbsp;</strong></td>
      <td align="right">&nbsp;</td>
      <td><strong><i class="icon-lock"></i>&nbsp;&nbsp;Password</strong></td>
    </tr>
    <tr>
      <td width="45%" height="32"><input type="text" name="username" id="textfield"></td>
      <td width="3%" align="right"></td>
      <td width="52%"><input type="password" name="password" id="textfield2"></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
        <td colspan="3" align="left"><button type="submit" class="btn btn-success"><i class="icon-upload"></i>&nbsp;Login&nbsp;&nbsp;</button>
      
        &nbsp;&nbsp;
        
    </tr>
  </table>
</form>
<p><br>
</p>
</body>
</html>





Code หน้า main_menu.php


Code (PHP)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>:: Home</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">

<!-- Le styles -->
<link href="assets/css/bootstrap.css" rel="stylesheet">
<style type="text/css">
/* Sticky footer styles
      -------------------------------------------------- */

      html, body {
	height: 100%;/* The html and body elements cannot have any padding or margin. */
}
/* Wrapper for page content to push down footer */
      #wrap {
	min-height: 100%;
	height: auto !important;
	height: 100%;
	/* Negative indent footer by it's height */
        margin: 0 auto -60px;
}
/* Set the fixed height of the footer here */
      #push, #footer {
	height: 60px;
}
#footer {
	background-color: #f5f5f5;
}

      /* Lastly, apply responsive CSS fixes as necessary */
      @media (max-width: 767px) {
 #footer {
 margin-left: -20px;
 margin-right: -20px;
 padding-left: 20px;
 padding-right: 20px;
}
}
/* Custom page CSS
      -------------------------------------------------- */
      /* Not required for template or sticky footer method. */

      #wrap > .container {
	padding-top: 60px;
}
.container .credit {
	margin: 20px 0;
}
code {
	font-size: 80%;
}
</style>
<link href="assets/css/bootstrap-responsive.css" rel="stylesheet">

<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
      <script src="../assets/js/html5shiv.js"></script>
    <![endif]-->

<!-- Fav and touch icons -->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="assets/ico/apple-touch-icon-57-precomposed.png">
<link rel="shortcut icon" href="assets/ico/favicon.png">
<style type="text/css">
body,td,th {
	color: #009933;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<body background="images/1180422460.gif">
<div class="navbar navbar-fixed-top">
  <div class="navbar-inner">
    <div class="container">
      <button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>
      <a class="brand" href="#">IT LIGHTSOURCE</a>
      <div class="nav-collapse collapse">
        <ul class="nav">
          <li><a href="main_menu.php"><i class="icon-home"></i>&nbsp;Home</a></li>
          <li><a href="education.php" target="_parent"><i class="icon-file"></i>&nbsp;Education</a></li>
          <li><a href="http://helpdesk.lightsource.co.th" target="_blank"><i class="icon-wrench"></i>&nbsp;Helpdesk</a></li>
          <li><a href="#"><i class="icon-barcode"></i>&nbsp;ลาออนไลน์</a></li>
          <!--</h1><li><a href="ind.php"><i class="icon-user"></i>&nbsp;Administrator</a></li>-->
          <li><a href="<?php echo $logoutAction ?>"><i class="icon-refresh"></i>&nbsp;Log out</a></li>
        </ul>
        </li>
        </ul>
      </div>
      <!--/.nav-collapse --> 
    </div>
  </div>
</div>
<p><br>
  <?php
 
    $date = date("Y-m-d");
    $time = date("H:i:s");
    ?>
</p>
<tr></tr>
<table width="100%" border="0">
  <tr>
    <td width="159" height="100" align="left">&nbsp;</td>
    <td width="369" height="100"align="center"><p><strong>&nbsp;&nbsp;<img src="images/mainmenulogo.png" width="300" height="72"></strong></p></td>
    <td width="172" align="center"></td>
  </tr>
</table>
<script src="js/bootstrap.min.js"></script>
<table width="100%" align="center" border="0" >
  <tr >
 	<td width="20%" align="center"><strong></strong></td>   
    <td width="11%" align="center"><a href="education.php" target="_parent"><img src="images/iconeducation.png" alt="education" longdesc="education.php"></a></td>
    <td width="1%" align="center"></td>
    <td width="11%" align="center"><a href="http://helpdesk.lightsource.co.th" target="_blank"><img src="images/iconhelpdesk.png" alt="helpdesk" longdesc="http://helpdesk.lightsource.co.th"></td>
    <td width="1%" align="center"><strong></strong></td>
    <td width="11%" align="center"><strong><img src="images/IconLaOnline.png" alt="LaOnline"></strong></td>
    <td width="1%" align="center"><strong></strong></td>
    <td width="11%" align="center"><a href="download.php" target="_parent"><img src="images/iconDownload.png" alt="helpdesk" longdesc="http://helpdesk.lightsource.co.th"></td>
    
    <td width="20%" align="center"><strong></strong></td>

  </tr>

</table>
<table width="100%" align="center" border="0" >
  <tr >
 	<td width="20%" align="center"><strong></strong></td>   
    <td width="11%" align="center">Education</td>
    <td width="1%" align="center"></td>
    <td width="11%" align="center">Helpdesk</td>
    <td width="1%" align="center"><strong></strong></td>
    <td width="11%" align="center">ลาออนไลน์</td>
    <td width="1%" align="center"><strong></strong></td>
    <td width="11%" align="center">Download</td>
    <td width="20%" align="center"><strong></strong></td>

  </tr>

</table>


<div class="row">

  <div class="span5" align="center">
    <table width="38%" height="46" border="0" align="center">
      <tr>
        <td height="42" align="center"><?php if ($pageNum_AJ > 0) { // Show if not first page ?>
            <a href="<?php printf("%s?pageNum_AJ=%d%s", $currentPage, 0, $queryString_AJ); ?>">
            <button type="button" class="btn btn-mini btn-success">&nbsp;&nbsp;<i class="icon-fast-backward"></i>&nbsp;&nbsp;</button>
            </a>
        <?php } // Show if not first page ?></td>
        <td align="center"><?php if ($pageNum_AJ > 0) { // Show if not first page ?>
            <a href="<?php printf("%s?pageNum_AJ=%d%s", $currentPage, max(0, $pageNum_AJ - 1), $queryString_AJ); ?>">
            <button type="button" class="btn btn-mini btn-success">&nbsp;&nbsp;<i class="icon-backward"></i>&nbsp;&nbsp;</button>
            </a>
        <?php } // Show if not first page ?></td>
        <td align="center"><?php if ($pageNum_AJ < $totalPages_AJ) { // Show if not last page ?>
            <a href="<?php printf("%s?pageNum_AJ=%d%s", $currentPage, min($totalPages_AJ, $pageNum_AJ + 1), $queryString_AJ); ?>">
            <button type="button" class="btn btn-mini btn-success">&nbsp;&nbsp;<i class=" icon-forward"></i>&nbsp;&nbsp;</button>
            </a>
        <?php } // Show if not last page ?></td>
        <td align="center"><?php if ($pageNum_AJ < $totalPages_AJ) { // Show if not last page ?>
            <a href="<?php printf("%s?pageNum_AJ=%d%s", $currentPage, $totalPages_AJ, $queryString_AJ); ?>">
            <button type="button" class="btn btn-mini btn-success">&nbsp;&nbsp;<i class="icon-fast-forward"></i>&nbsp;&nbsp;</button>
            </a>
        <?php } // Show if not last page ?></td>
      </tr>
    </table>
  </div>
</div>

<!-- Le javascript
    ================================================== --> 
<!-- Placed at the end of the document so the pages load faster --> 
<script src="assets/js/jquery.js"></script> 
<script src="assets/js/bootstrap-transition.js"></script> 
<script src="assets/js/bootstrap-alert.js"></script> 
<script src="assets/js/bootstrap-modal.js"></script> 
<script src="assets/js/bootstrap-dropdown.js"></script> 
<script src="assets/js/bootstrap-scrollspy.js"></script> 
<script src="assets/js/bootstrap-tab.js"></script> 
<script src="assets/js/bootstrap-tooltip.js"></script> 
<script src="assets/js/bootstrap-popover.js"></script> 
<script src="assets/js/bootstrap-button.js"></script> 
<script src="assets/js/bootstrap-collapse.js"></script> 
<script src="assets/js/bootstrap-carousel.js"></script> 
<script src="assets/js/bootstrap-typeahead.js"></script>
</body>
</html>
<?php

?>




Tag : PHP







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2016-02-24 10:53:27 By : nuengbefree View : 1075 Reply : 4
 

 

No. 1

Guest


1. หน้า index.php
บรรทัดแรก <?php ให้แก้เป็น

Code (PHP)
<?php
session_start();


และบรรทัด echo "<meta http-equiv='refresh' content='0 ;url=main_menu.php'>" ;
ให้แก้เป็น

Code (PHP)
$_SESSION['sess_login'] = 'login';
header("Location: main_menu.php");
exit();


2. หน้า main_menu.php
บรรทัดบนสุดของหน้าให้เพิ่ม

Code (PHP)
<?php
session_start();
if($_SESSION['sess_login']==''){
   header("Location: index.php");
   exit();
}
?>







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-02-24 12:55:49 By : NAT
 


 

No. 2



โพสกระทู้ ( 5 )
บทความ ( 0 )



สถานะออฟไลน์


ขอบคุณมากครับผม แล้วถ้าผมจะทำปุ่ม log out ต้องใช้คำสั่งอันไหนครับผม
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-02-25 11:50:07 By : nuengbefree
 

 

No. 3



โพสกระทู้ ( 5 )
บทความ ( 0 )



สถานะออฟไลน์


Error
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\AppServ\www\it\main_menu.php:1) in C:\AppServ\www\it\main_menu.php on line 2

Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\it\main_menu.php:1) in C:\AppServ\www\it\main_menu.php on line 4



ผมลองเรียกหน้า main_menu.php โดยตรง ขึ้นฟ้องดังข้างบนครับผมมีวิธีแก้มั้ยครับผม
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-02-25 13:25:21 By : nuengbefree
 


 

No. 4



โพสกระทู้ ( 586 )
บทความ ( 0 )



สถานะออฟไลน์


แบบที่ผมเคยทำก็ ทุกหน้าสามารถเข้าได้เมื่อมีการ Login แล้วผมจะ Include(xxx.php)

ซึ่งใน xxx.php จะมี function ในการตรวจสอบว่ามี การ Login แล้วหรือเปล่าอ่ะครับ หากไม่มีก็จะ Redirect ไปยังหน้า Login อ่ะครับ ประมาณนี้

Code (PHP)
function require_login() {
	
/* this function checks to see if the user is logged in. if not, it will show
* the login screen before allowing the user to continue */
	global $CFG, $_COOKIE;
	
	if(!isset($_COOKIE['user_id'])){
		header('Location:index.php');
		break;
	}
}



ส่วนหน้า Logout ก็จะมีคำสั่ง ทำลาย Cookie ไปอ่ะครับ

Code (PHP)
<?php session_start(); 

setcookie('user_id','', 0,'/');
setcookie('pos_id','', 0,'/');
setcookie('username','', 0,'/');
setcookie('fullname','', 0,'/');
setcookie('position','', 0,'/');
setcookie('email_cookie','', 0,'/');
setcookie('tel_cookie','', 0,'/');

header('Location:index.php');
?>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-02-26 10:54:14 By : nut_ch31
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : สอบถาม php ครับ เวลาล็อคอินผ่านหน้า log in ไปแล้วเข้าหน้าหลัก ถ้าไม่ให้เข้าหน้าหลักโดยตรงต้องทำยังงัย
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่