|
|
|
สอบถามเรื่องการวางตำแหน่งให้รหัสรูปภาพให้เช็ครหัสรูปภาพได้จากหน้า login |
|
|
|
|
|
|
|
คือตอนนี้ผม login เข้าระบบอีกหน้าได้นะครับแต่ปัญหาคือว่า ตรงส่วนของรหัสรูปภาพซึ่งผมนำมาใส่ ตอนนี้มันเช็คได้อย่างเดียวคือต้องใส่รหัสรูปภาพถึงจะเข้าได้ แต่ไม่ได้เช็คว่ารหัสถูกหรือเปล่า ก็เลยอยากขอคำแนะนำเรื่องนี้หน่อยครับว่าจะทำยังไง ขอบคุณล้วงหน้าครับผม
index.php
<?php
session_start();
//ดึงไฟล์เชื่อมต่อกับฐานข้อมูลเข้ามาใช้
include("config.inc.php");
if(isset($_SESSION["valid_user"])){ //ตรวจสอบว่ามีผู้ใช้login แล้วยัง ถ้ามีแล้วก็จะแสดงข้อความว่า คุณได้เข้าสู่ระบบแล้ว
echo"คุณได้เข้าสู่ระบบแล้ว";
echo'<hr><a href="logout.php">ออกจากระบบ</a><hr>';
}else{
if(isset($_POST["send"]))
process_form();
else
show_form();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<script language="JavaScript">
function check(){
if(document.checkForm.user.value==""){
alert("กรุณากรอกชื่อผู้เข้าใช้งานด้วยครับ");
document.checkForm.user.focus();
return false;
}
else if(document.checkForm.pass.value==""){
alert("กรุณากรอก รหัสผ่าน ด้วยครับ");
document.checkForm.user.focus();
return false;
}else if(document.checkForm.captcha.value==""){
alert("กรุณากรอก รหัสรูปภาพ");
document.checkForm.user.focus();
return false;
}else
return true;
}
</script>
<body>
<?php
//ฟังชันที่ใช้เเสดงฟอร์ม
function show_form(){
?>
<form id="checkForm" name="checkForm" method="post" action="<?php {$_SERVER['file:///C|/Users/User/Downloads/PHP_SELF'];}?>"onSubmit="return check()">
<table width="285" border="6" align="center">
<tr>
<td align="center" bgcolor="#99FFCC"><p>ระบบจัดเก็บข้อมูลนักศึกษา</p></td>
</tr>
</table>
<p> </p>
<table width="240" border="0" align="center">
<tr>
<td colspan="2" bgcolor="#999999">ชื่อผู้ใช้ :</td>
<td width="10" rowspan="11"> </td>
</tr>
<tr>
<td colspan="2" align="center" bgcolor="#FFFFFF"><input type="text" name="user" id="user" /></td>
</tr>
<tr>
<td colspan="2" align="center">------------------------------</td>
</tr>
<tr>
<td colspan="2" bgcolor="#999999">รหัสผ่าน :</td>
</tr>
<tr>
<td colspan="2" align="center" bgcolor="#FFFFFF"><input name="pass" type="password" id="pass" /></td>
</tr>
<tr>
<td colspan="2" align="center">------------------------------</td>
</tr>
<tr>
<td colspan="2" align="center" bgcolor="#000000"><img src="create_captcha.php" width="106" height="54" border="2" /></td>
</tr>
<tr>
<td colspan="2" align="center" bgcolor="#999999">.กรุณากรอกข้อความด้านบน</td>
</tr>
<tr>
<td colspan="2" align="center"><p>
<input type="text" name="captcha" id="captcha" />
</p></td>
</tr>
<tr>
<td width="107" align="right"><input type="submit" name="send" id="button" value="เข้าสู่ระบบ" /></td>
<td width="109"><input type="reset" name="Submit222" id="button2" value="ยกเลิก" /></td>
</tr>
<tr>
<td colspan="2" align="center"><a href="menu.php"> <<< Back Page >>> </a></td>
</tr>
</table>
</form>
<p>
<?php
}
function process_form(){
$user=trim($_POST["user"]);
$pass=trim($_POST["pass"]);
//ตรวจสอบผู้ใช้งานจากฐานข้อมูล
$sql="SELECT*FROM admin WHERE(Username='$user')AND(Password='$pass')";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$user=$row["Username"];
$name=$row["LoginName"];
//จับการตรวจสอบ
if(($user!="")&&($name!="")){
$_SESSION["valid_user"]=$user;//ประกาศตัวแปร session เพื่อให้เรียกใช้ได้ในทุกๆหน้า
$_SESSION["valid_name"]=$name;
echo"<meta http-equiv=\"refresh\"content=\"0;URL=Student_Show.php\">";//edit//echo"สวัสดีคุณ$name";
}else{
echo'<div align="center"<font color="red">ชื่อผู้ใช้และรหัสผ่านไม่ถูกต้อง</font></div>';
show_form();
}}
?>
</body>
</html>
create_captcha.php
<?php
session_start();
$str = md5(crypt("captcha"));
$captcha = strtoupper(substr($str, 0, 9));
$_SESSION['captcha'] = $captcha;
$img = imageCreate(55, 35);
$bg = imageColorAllocate($img, 0, 0, 0);
$color = imageColorAllocate($img, 255, 255, 255);
imageString($img, 5, 10, 10, "$captcha", $color);
header("Content-type: image/gif");
imageGif($img);
imageDestroy($img);
?>
Tag : PHP, JavaScript
|
|
|
|
|
|
Date :
2014-02-05 23:55:04 |
By :
boy |
View :
707 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ติดปัญหาตรงไหนครับ
|
|
|
|
|
Date :
2014-02-06 09:43:56 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตรงการเขียนโค๊ดเช็ครหัสรูปภาพว่าถูกต้องหรือเปล่าที่กรอกมา ตอนนี้ผมทำได้แค่เช็ดว่าต้องใส่รหัสรูปภาพเท่านั้นเอง มันเป็นโค๊ดที่ใช้เรียนในห้องอะครับพอดีอาจารย์เขาให้ออกแบบระบบโดยดัดแปลงเอา ผมเห็นว่ารหัสรูปภาพมันน่าสนใจดี เลยเอามาใส่แต่ก็ทำได้แค่ส่วนเช็คว่ากรอกหรัสรูปภาพหรือยังแค่นั้นเองครับ
|
|
|
|
|
Date :
2014-02-06 09:59:22 |
By :
boy |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เช็คจากตัวแปร session ครับ
Code (PHP)
if($_SESSION['captcha'] == $_POST['captcha']){
echo 'คุณกรอก captcha ถูกต้อง';
} else {
echo 'คุณกรอก captcha ไม่ถูกต้อง';
}
|
|
|
|
|
Date :
2014-02-06 10:47:50 |
By :
arm8957 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|