2017-09-28 24 views
-1

私はウェブサイト上で作業しています。しかし、私はそれに問題がある、私はログインフォームに記入すると、それは読み込みページに立ち往生する。登録ユーザーのユーザーリストを検索していないようです。ログインページが動作しません、html

私はこれに新しいので、私に同行してください。以下

以下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> 

ある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である

<?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フォーム

コードの他の部分が必要な場合は教えてください。

+2

それは簡単なようです。あなたのHTMLフォームはPOSTを指定します。したがって、ログインデータはPOST経由で送信されます。しかし、あなたのlogin.phpではGETを使ってデータを取得しようとします。これをPOSTに変更します。 – natheriel

答えて

0

の変更は、あなたのlogin.phpファイルに次と試してみてください。

<?php 
if ($_SERVER['REQUEST_METHOD'] == 'POST'){//Made change here 
    use `$_REQUEST` instead of `$_GET`. 
    //Your logic comes here. 
} 
?> 
+1

また、 '$ _GET'は' $ _POST'に変更する必要があります。 –

+0

@ B.Desai新しい編集でそれを言及しました。 –

+0

クイック質問、@KetanSolankiこの行は、 '$ _GET'の代わりに' $ _REQUEST'を使用するか、$ _REQUESTにすべての$ _GETを変更するだけです。 –

関連する問題