What are the best practices for ensuring the stability and reliability of a PHP-based router login system?
Issue: To ensure the stability and reliability of a PHP-based router login system, it is important to implement proper security measures such as input validation, password hashing, and session management.
// PHP code snippet for implementing secure login system
// Validate user input
$username = filter_var($_POST['username'], FILTER_SANITIZE_STRING);
$password = filter_var($_POST['password'], FILTER_SANITIZE_STRING);
// Hash the password
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
// Verify user credentials
if ($username === 'admin' && password_verify($password, $hashed_password)) {
// Start a session and set user as logged in
session_start();
$_SESSION['logged_in'] = true;
// Redirect to router dashboard
header('Location: router_dashboard.php');
exit;
} else {
// Display error message
echo 'Invalid username or password';
}
Related Questions
- How can PHP functions like explode, array_merge, and array_unique be utilized to manipulate and sort data retrieved from a database?
- Are there any best practices for formatting numbers in PHP to avoid incorrect output?
- What are the potential pitfalls of directly using user input in a MySQL query in PHP?