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
- What is the correct syntax for retrieving form data in PHP using the POST method?
- How can mod_rewrite usage in PHP scripts contribute to a webpage being loaded multiple times?
- What are some common pitfalls when migrating PHP code from version 4 to version 7, especially in relation to object instantiation?