簡體   English   中英

在 PHP 中驗證數據庫中的用戶名和密碼后,如何使按鈕轉到特定頁面

[英]How do you make a button go to a specific page after validating the Username and Password from the Database in PHP

我一直在嘗試讓按鈕在驗證用戶輸入正確的用戶名/密碼后轉到頁面,我已經部分完成了,問題是當我單擊按鈕時它不會驗證用戶名/password,它只會轉到位置。 我正在使用 HTML、CSS、javascript 和 PHP。 這是代碼。

<?php
// include database and object files
include_once '../config/database.php';
include_once '../objects/user.php';

// get database connection
$database = new Database();
$db = $database->getConnection();

// prepare user object
$user = new User($db);
// set ID property of user to be edited
$user->username = isset($_GET['username']) ? $_GET['username'] : die();
$user->password = base64_encode(isset($_GET['password']) ? $_GET['password'] : die());
// read the details of user to be edited
$stmt = $user->login();
header('Location: ../../../../Home/index.html');
if($stmt->rowCount() > 0){
    // get retrieved row
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    // create array
    $user_arr=array(
        "status" => true,
        "message" => "Successfully Login!",
        "id" => $row['id'],
        "username" => $row['username']
    );
}
else{
    $user_arr=array(
        "status" => false,
        "message" => "Invalid Username or Password!",
    );
}
// make it json format
print_r(json_encode($user_arr));
?>

這是一個視頻... https://youtu.be/Li__rDSdEbs

問題是您在獲取用戶數據之前定位到另一個頁面,

if($stmt->rowCount() > 0){
// get retrieved row
$row = $stmt->fetch(PDO::FETCH_ASSOC);
// create array
$user_arr=array(
    "status" => true,
    "message" => "Successfully Login!",
    "id" => $row['id'],
    "username" => $row['username']
);
header('Location: ../../../../Home/index.html');}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM