且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使登录更安全

更新时间:2022-12-19 17:08:59

安全。
首先,在登录页面(例如 login.php )将用户重定向到 loginhome.php

You can use a PHP Session instead to make it more secure. Firstly, redirect users to loginhome.php in the Login Page (eg. login.php).

session_start();
$_SESSION['logged_in'] = true;
header("Location: loginhome.php");

loginhome.php 文件中,你可以检查会话,如果没有设置,然后重定向用户回到登录页面。

And in the loginhome.php file, you can check for the session, if not set, then redirect users back to the Login Page.

<?php

 include "include.php";
 session_start();
 if(!$_SESSION['logged_in']){
 session_destroy();
 header("Location: login.php");
}

?>

要注销,请销毁Session。

To logout, destroy the Session.

<?php

session_start();
$_SESSION['logged_in'] = 0;
session_destroy();
header("Location: login.php");

?>

include.php 档案。

<?php
$link = mysqli_connect
("host", "user", "password", "database");
?>

只是提示,您应该加密用户的用户名和密码。希望这有助于!

Just a tip, you should encrypt the users' usernames and passwords. Hope this helps!