내 질문에 here을 게시하고 게시물을 편집하기 전에 으로 실제 질문이 닫혀 있지 않습니다.!데이터베이스의 사용자 이름과 암호 확인 (스크립트 포함)
보시다시피<html>
<head>
<title>Password Checking Script</title>
</head>
<body>
<form action="check_user-pass.php" method="POST">
<h3>Please Login</h3>
User Name: <input type="text" name="user_name"><br>
Password: <input type="password" name="password">
<input type="submit" name="submit" value="Login!">
</form>
</body>
</html>
,이 양식 check_user-pass.php
을 통해 사용자를 인증 :
는이 같은 로그인 폼이 있습니다.
내 데이터베이스에서 해당 자격 증명을 찾습니다. 있을 경우 OK
을 반환하고 그렇지 않으면 값 NO
을 반환합니다.
제 질문은 정확히 check_user-pass.php
에 어떤 코드를 포함시켜야합니까?
더 많은 코드를 추가하려고했지만 그럴 수도 없었습니다! 나의 현재 코드는 다음과 같습니다
<?php
ob_start();
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("$db_name") or die(mysql_error());
echo "Connected to Database<br />";
// Check $username and $password
/*
if(empty($_POST['username']))
{
echo "UserName/Password is empty!";
return false;
}
if(empty($_POST['password']))
{
echo "Password is empty!";
return false;
}
*/
// Define $username and $password
$username=$_POST['username'];
$password=md5($_POST['pass']);
// To protect MySQL injection (more detail about MySQL injection)
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$sql="SELECT * FROM $tbl_name WHERE username='$username' and password='$password'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $username and $password, table row must be 1 row
if ($count==1) {
echo "Success! $count";
} else {
echo "Unsuccessful! $count";
}
ob_end_flush();
?>
이 코드가 작동해야합니다. 당신이 겪고있는 문제는 무엇입니까 ?? –
@PdsIr ** StackOverflow에 오신 것을 환영합니다! ** [faq] (http://stackoverflow.com/faq)을 반드시 읽으십시오. –