나는 웹 사이트에서 일하고 있습니다. 하지만 문제가 생겼습니다. 로그인 양식을 채울 때로드 페이지에서 멈추게됩니다. 등록 된 사용자를 찾기 위해 사용자 목록을 검색하는 것 같지 않습니다.로그인 페이지가 작동하지 않음, html
저는이 문제에 익숙하지 않으므로 저와 함께주십시오.
다음은 다음은 login.php 아래
<?php
include_once ("dbconnection.php");
session_start(); //always start a session in the beginning
if ($_SERVER['REQUEST_METHOD'] == 'GET')
{
if (empty($_GET['user']) || empty($_GET['pass'])) //Validating inputs using
PHPcode
{
echo "Incorrect username or password";
// header("location: LoginForm.php");//You will be sent to Login.php for re-
login
}
$userName = $_GET["user"]; // as the method type in the form is "post" we
areusing $_POSTotherwiseitwouldbe $_GET[]$password = $_GET["pass"];
$stmt = $db->prepare("SELECT USER, PASS FROM WEBSITEUSERS WHERE USER = ?");
// Fetching all the records with input credentials
$stmt->bind_param("s", $username); //You need to specify values to each '?'
explicitly
while usingpreparedstatements $stmt->execute();
$stmt->bind_result($UsernameDB, $PasswordDB); // Binding i.e. mapping
databaseresultstonew variables
// Compare if the database has username and password entered by the user.
Passwordhastobedecrpted
while comparing .
if ($stmt->fetch() && password_verify($password, $PasswordDB))
{
$_SESSION['user'] = $userName; //Storing the username value in session
variablesothatitcanberetrievedonotherpagesheader("location: userprofile.php"); // user will be taken to profile page
}
else
{
echo "<br />Incorrect username or password";
?>
<br /><a href="LoginForm.php">Login</a>
<?php
}
}
?>
가 dbconnection.php 아래
<?php
//Establishing connection with the database
define('DB_HOST', 'localhost');
define('DB_NAME', '');
define('DB_USER', '');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'WebsiteUsers');
$db = mysqli_connect(DB_HOST,DB_NAME,DB_PASSWORD,DB_USER);
?>
가 userprofile.php
입니다입니다 LoginForm.php<form name="login" method="post" action="login.php" onsubmit="return
validate();" >
<div>Username: </br><input type="text" name="user" /> </div>
</br>
<div>Password: </br><input type="password" name="pass" /> </div>
</br>
<div><input type="submit" value="Login" style="background-color: #1daa87;
border: none; color: black; padding: 8px 52px;"></input> <input
type="reset" value="Reset" style="background-color: #1daa87; border: none;
color: black; padding: 8px 52px;"></input></div>
</form>
입니다
<?php
session_start();
$username = $_SESSION['user']; //retrieve the session variable
?>
<center><h1>User Profile </h1></center>
<br/>
<b>Welcome <?php
echo $user ?> </b>
<div style="text-align: right"><a href="logout.php">Logout</a></div> <!--
calling Logout.php to destroy the session -->
<?php
if (!isset($_SESSION['user'])) //If user is not logged in then he cannot
accesstheprofilepage
{
// echo 'You are not logged in. <a href="login.php">Click here</a> to log
in .;
header("location:LoginForm.php");
}
?>
당신은 당신은 어떤 값을 입력 할 수 있습니다 [test.laveshpillay.com/LoginForm.php][1]
에서 로그인 양식을 시도 할 수 있으며 검증없이 로딩 화면에 당신을 데려 갈 것이며, 그것은 단지 것이다 login.php 양식
코드의 다른 부분이 필요한 경우 알려주십시오.
. HTML 양식에서 POST를 지정합니다. 따라서 로그인 데이터는 POST를 통해 전송됩니다. 그러나 login.php에서 GET을 통해 데이터를 얻으려고합니다. 그것을 POST로 변경하십시오. – natheriel