내 index.php 파일에이 스 니펫이 있습니다. 사용자에게 로그온하라는 메시지가 표시됩니다. 세부 정보가 데이터베이스 시스템에 없으면 index.php 페이지를 새로 고침하고 "유효하지 않은 자격 증명, 다시 시도하십시오"또는 이와 비슷한 메시지를 표시하려고합니다.PHP, 페이지를 다시로드하고 잘못된 자격 증명 메시지를 표시 하시겠습니까?
어떻게하면됩니까? 마지막 else
에서
<?php
session_start();
//Check if user is already logged in
if(!isset($_POST['id']))
{
$message = 'User is logged in already';
}
//Check the username and password have been submitted
if(!isset($_POST['Username'], $_POST['Password']))
{
$message = 'Please enter a valid username and password';
}
//Check the username is the correct length
else if (strlen($_POST['Username']) > 20 || strlen($_POST['Username']) < 4)
{
$message = 'Incorrect Username length, please try again';
}
//Check the password is the correct length
else if (strlen($_POST['Password']) > 20 || strlen($_POST['Password']) < 4)
{
$message = 'Incorrect Password length, please try again';
}
//Check the username only has alpha numeric characters
else if (ctype_alnum($_POST['Username']) != true)
{
$message = "Username must be alpha numeric";
}
else if (ctype_alnum($_POST['Password']) != true)
{
$message = "Password must be alpha numeric";
}
else
{
$admin = "****";
$adminPassword = "****";
//Enter the valid data into the database
$username = filter_var($_POST['Username'], FILTER_SANITIZE_STRING);
$password = filter_var($_POST['Password'], FILTER_SANITIZE_STRING);
//Encrypt the password
$password = sha1($password);
//Connect to the database
$SQLusername = "";
$SQLpassword = "";
$SQLhostname = "";
$databaseName = "";
try
{
//connection to the database
$dbhandle = mysql_connect($SQLhostname, $SQLusername, $SQLpassword)
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
//select a database to work with
$selected = mysql_select_db($databaseName, $dbhandle)
or die("Could not select database");
$selectCustomers = "SELECT * FROM
customers WHERE name =
'$username' AND password = '$password'";
$selectEmployees = "SELECT * FROM
employees WHERE name =
'$username' AND password = '$password'";
$selectAdmin = "SELECT * FROM
employees WHERE name =
'$admin' AND password = '$adminPassword'";
$customerResult = mysql_query($selectCustomers) or die(mysql_error());
$employeeResult = mysql_query($selectEmployees) or die(mysql_error());
$adminResult = mysql_query($selectAdmin) or die(mysql_error());
if(mysql_num_rows($customerResult) >= 1)
{
header("Location: memberPage.php");
$_SESSION["customer"] = "customer";
}
else if(mysql_num_rows($employeeResult) >= 1)
{
header("Location: adminPage.php");
$_SESSION["admin"] = "admin";
}
else if(mysql_num_rows($adminResult) >= 1)
{
header("Location: adminPage.php");
$_SESSION["admin"] = "admin";
}
else
{
header("Location: index.php");
}
//close the connection
mysql_close($dbhandle);
}
catch(Exception $e)
{
$message = 'We are unable to process your request. Please try again later"';
}
}
?>
<html>
<head>
<title>Login</title>
</head>
<body>
</body>
</html>
당신이 더 많은 코드를지나시겠습니까? 전에 당신이 질문을 한 것 같아요. –
그래서 어떤 오류가 표시되고 .. 어떤 블록이 실행되고 있습니까? "유효하지 않은 자격 증명 ..."을 간단히 표시 할 수 있지만 헤더가 작동하지 않을 수 있습니다. – Riad
물론 지금 전체 index.php 파일을 복사했습니다. – user2757842