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 > รบกวนช่วยดู code ให้หน่อยครับ ต้องการเช็ค user ที่อยุ่ในฐานข้อมูลแล้วให้เด้งไปหน้าอื่นครับ



 

รบกวนช่วยดู code ให้หน่อยครับ ต้องการเช็ค user ที่อยุ่ในฐานข้อมูลแล้วให้เด้งไปหน้าอื่นครับ

 



Topic : 109419



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



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



หน้า Login

Code (PHP)
<?php
session_start();
?>

<!doctype html>
<!--[if lt IE 7]> <html class="ie6 oldie"> <![endif]-->
<!--[if IE 7]>    <html class="ie7 oldie"> <![endif]-->
<!--[if IE 8]>    <html class="ie8 oldie"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="">
<!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>กรุณาเข้าสู่ระบบ</title>
<link href="include/boilerplate.css" rel="stylesheet" type="text/css">
<link href="include/main_layout.css" rel="stylesheet" type="text/css">
<link href="include/config.php" >
<!-- 
To learn more about the conditional comments around the html tags at the top of the file:
paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/

Do the following if you're using your customized build of modernizr (http://www.modernizr.com/):
* insert the link to your js here
* remove the link below to the html5shiv
* add the "no-js" class to the html tags at the top
* you can also remove the link to respond.min.js if you included the MQ Polyfill in your modernizr build 
-->
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<script src="include/respond.min.js"></script>
<script type="text/javascript" src="ajax/ajaxlogin.js"></script>

<body>
<div class="gridContainer clearfix">
  <div id="header" align="center"><img src="images/602_527538127283206_1902571865_n.jpg"></div>
  <div id="contain">
  <div id="login_table">
  <form name="frm_login" id="frm_login" action="Welcome-page.php">
  <table border="0" cellspacing="0" cellpadding="3" align="center" style="width:300px">
<?php
// เช็คตัวแปรuserว่ามีอยุ่จริงรึเปล่า ถ้ามีอยุ่จริงให้ทำกระบวนการที่ 1 ถ้าเท็จให้ทำกระบวนการที่ 2
  if (isset($_SESSION['user'])) { 
  	echo ""; // กระบวนการที่1 ให้เด้งไปหน้าWelcome-page.php
  }else{
//กระบวนการที่2
	echo "<tr><td colspan=2 align=center><strong>ยินดีต้อนรับ<br>ระบบสั่งเปิดปิดอุปกรณ์ไฟฟ้าผ่านเว็บแอพพลิเคชั่น</strong></td></tr>";
	echo "<tr><td align=right  width=45%><label for=user>Username :</label></td><td><input type=text name=txtuser id=txtuser onKeyUp=check_data(this.value)></td></tr>";
	echo "<tr><td align=right><label for=password>Password :</label></td><td><input type=password name=txtpassword 
	id=txtpassword></td></tr>";
    echo "<tr><td align=right valign=top>พิมพ์อักขระสีแดงในภาพ:</td><td><img id=imgCaptcha src=redcaptcha.php /><br><input type=text id=txtCaptcha name=txtCaptcha size=3 maxlength=3><img src=images/icon_refresh.jpg width=17 height=18 border=0 onClick=\"javascript:refreshCap()\"><br><div id=msg3></div></td></tr>"; 
	echo "<tr><td colspan=2 align=center><input name=submit type=submit id=submit value=เข้าสู่ระบบ src=Welcome.php onClick=\"return check_login(frm_login.txtuser.value, frm_login.txtpassword.value,'LOGIN')\"/><br><a href=forgot_pwd.php target=_blank>ลิมรหัสผ่าน</a></td></tr>";
  }
?>	
	 
	</table>
  </form>

  </div>
  </div>
</div>
  <div id="footer" align="center">มหาวิทยาลัยราชภัฎสวนดุสิต ศูนย์การศึกษานอกที่ตั้งตรัง<br><a href="http://www.dusittrang.com" target="_blank">www.dusittrang.com</a></div>
</div>

</body>
</html>



หน้าAjaxlogin.js
Code (JavaScript)
function newXmlHttp(){
var xmlhttp = false;

  try{
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  }catch(e){
	  try{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  }catch(e){
		xmlhttp = false;
	  }
  }

  if(!xmlhttp && document.createElement){
    xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}

/*สร้างฟังก์ชั่น check_login() เพื่อตรวจสอบความถูกต้องของข้อมูลก่อนส่งไปยังเพจปลายทาง*/
function check_login(user, password, Mode) {
  var cancle=false;
    if (user.length==0) {
      alert('กรุณาป้อน Username ก่อน');
      document.frm_login.txtuser.focus(); 
      cancle=true;
    } else if (password.length==0) {
      alert('กรุณาป้อน Password ก่อน') ;
      document.frm_login.txtpassword.focus(); 
      cancle=true;
    }
	
  if (cancle==false) {
    doLogin(Mode);		
  }
  return false;
}

/*สร้างฟังก์ชั่น doLogin() เพื่อส่งข้อมูลไปยังเพจปลายทาง*/
function doLogin(Mode) {
 	
  var url = 'checkuser.php';
  var pmeters = "&tLogin=" + encodeURI( document.getElementById("txtuser").value) +
    "&tPassed=" + encodeURI( document.getElementById("txtpassword").value) +
    "&action=" + Mode ;	
  xmlhttp = newXmlHttp();
  xmlhttp.open('POST',url,true);

  xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlhttp.setRequestHeader("Content-length", pmeters.length);
  xmlhttp.setRequestHeader("Connection", "close");
  xmlhttp.send(pmeters);
				
  xmlhttp.onreadystatechange = function()
  {

    if(xmlhttp.readyState == 3)  // Loading Request
    {
      document.getElementById("login_table").innerHTML = "Now is Loading...";
    }

    if(xmlhttp.readyState == 4) // Return Request
    {
		if (xmlhttp.responseText=="Y") {
			document.getElementById("login_table").innerHTML = '<font color=red size=1>Username หรือ Password ไม่ถูกต้อง</font>';
			document.getElementById("txtuser").value = '';	
			document.getElementById("txtpassword").value = '';	
		} else {
			window.location.href="Welcome-page.php";
		}
    }
				
  }	

}

function doExit(name, Mode) {
	
  var url = 'checkuser.php';
  var pmeters = "user=" + name +
    "&action=" + Mode ;	  
  xmlhttp = newXmlHttp();
  xmlhttp.open('POST',url,true);

  xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlhttp.setRequestHeader("Content-length", pmeters.length);
  xmlhttp.setRequestHeader("Connection", "close");
  xmlhttp.send(pmeters);
				
  xmlhttp.onreadystatechange = function()
  {
    if(xmlhttp.readyState == 4) // Return Request
    {
		window.location.href="Login-page.php";
    }
				
  }	

}

function forgot_pwd(email) {
  var cancle=false;
    if (email.length==0) {
      alert('กรุณาป้อน Email ก่อน');
      document.form1.txtemail.focus(); 
      cancle=true;
    }
	
  if (cancle==false) {
	 var url = 'forgot_pwd.php';

	 var pmeters = "tEmail=" + encodeURI( document.getElementById("txtemail").value );			 	 

	 xmlhttp = newXmlHttp();
	 xmlhttp.open('POST',url,true);

	 xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	 xmlhttp.setRequestHeader("Content-length", pmeters.length);
	 xmlhttp.setRequestHeader("Connection", "close");
	 xmlhttp.send(pmeters);
				
	 xmlhttp.onreadystatechange = function()
	 	 {

	 	 if(xmlhttp.readyState == 3)  // Loading Request
	 	 {
	 	 	 document.getElementById("result").innerHTML = "Now is Loading...";
	 	 }

	 	 if(xmlhttp.readyState == 4) // Return Request
	 	 {
			document.getElementById("result").innerHTML = xmlhttp.responseText;
			document.getElementById("txtemail").value = '';	
		 }
		 }
			 
  }
  return false;
}




Tag : PHP, JavaScript, Ajax







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2014-06-23 18:51:05 By : zephyrzeez View : 941 Reply : 1
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

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

Code (JavaScript)
		if (xmlhttp.responseText=="Y") {
			document.getElementById("login_table").innerHTML = '<font color=red size=1>Username หรือ Password ไม่ถูกต้อง</font>';
			document.getElementById("txtuser").value = '';	
			document.getElementById("txtpassword").value = '';	
		} else {
			window.location.href="Welcome-page.php";
		}


อยากให้ไปไหนก็ใส่ window.location.href="URL.php";






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-06-24 09:01:27 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : รบกวนช่วยดู code ให้หน่อยครับ ต้องการเช็ค user ที่อยุ่ในฐานข้อมูลแล้วให้เด้งไปหน้าอื่นครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 04
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 อัตราราคา คลิกที่นี่