|
 |
|
อยากให้พี่ช่วยแก้โค้ด การใช้งานร่วมกันระหว่างระบบ log in ที่ใช้ตรวจสอบจากไฟล์ .txt และ การเก็บตัวแปรเป็นแบบsession |
|
 |
|
|
 |
 |
|
ข้อมูลที่ต้องทำ มีดังนี้อะครับ
1โปรแกรมจะรับชื่อผู้ใช้(User Name) และรหัสผ่าน(Password)จากผู้ใช้ จากนั้นก็อ่านไฟล์ข้อมูลผู้ใช้งาน(Account.txt)เพื่อตรวจสอบความถูกต้อง
2หากผู้ใช้เข้าสู่ระบบสำเร็จ ต้องมีการเก็บข้อมูลชื่อ(Name) และ (Username)ไว้ในตัวแปร session
3มีการตรวจสอบว่าผู้ใช้ป้อนข้อมูลหรือไม่
4การทำงานต่างๆต้องทำงานในฟังก์ชันเท่านั้น
5การตรวจสอบข้อมูลผู้ใช้ต้องทำหลังการsubmit
6การแยกข้อมูลชื่อผู้ใช้กับรหัสได้ดังนี้
-การใช้ฟังก์ชัน strpos เพื่อหาตำแหน่งของ Coln จากนั้นใช้ฟังก์ชัน substrเพื่อสกัดข้อความได้
7การอ่านไฟล์สามารถใช้ฟังก์ชัน fopen ได้
code หน้าแรกครับ(Login.php)
Code (PHP)
<html>
<title>Login</title>
<head>
</head>
<body>
<form id="form1" name="form1" method="post" action="IOfile_strpos.php">
Please Login To Order <br />
User Name : <input type="text" name="userName" id="userName" size=40 /> <br />
Password : <input type="text" name="passWord" id="passWord" size=40 /> <br />
<button type="submit" value="Log In">Log In</button>
</form>
</body>
code หน้าตรวจสอบการlog in ครับ(IOfile_strpos.php)
<?php
function functionStrpos(){
$file = "Account.txt";
$fileOpen = fopen($file, "r");
while (!feof($fileOpen)){
$userName = fgets($fileOpen, 4096);
$checkUser = substr($userName,0 , strpos ($userName, ':'));
$checkPass = substr($userName, strpos($userName, ':')+1);
if(trim($_POST['userName']) == trim($checkUser) && trim($_POST['passWord']) == trim($checkPass))
{
$true = "correct";
}
}
fclose($fileOpen);
if($true == "correct"){
echo "MACTH - user/pass correct";
echo "User Name: ".$_POST['userName']."<br />";
echo "PASSWORD: ".$_POST['passWord']."<br />";
}else{
echo "Invalid User ACCOUNT - user/pass doesn't matched <br />";
echo "Please, Try again !!!!";
}
}
echo functionStrpos();
?>
</html>
ช่วยผมหน่อยนะครับพี่ๆทุกท่าน
Tag : PHP, HTML/CSS, CakePHP

|
|
 |
 |
 |
 |
Date :
2012-02-18 17:31:47 |
By :
natthawat |
View :
993 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากๆครับ
|
 |
 |
 |
 |
Date :
2012-02-19 13:39:33 |
By :
natthawat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|