In what scenarios would implementing a login system be a more secure option than relying on IP-based access control for an Intranet site?
Implementing a login system would be a more secure option than relying on IP-based access control for an Intranet site in scenarios where multiple users need access from different locations or devices within the same network. This is because IP addresses can be easily spoofed or shared, making it possible for unauthorized users to gain access. A login system, on the other hand, requires users to provide unique credentials, adding an extra layer of security.
<?php
session_start();
if(isset($_POST['username']) && isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
// Validate username and password against a database
if($username === 'admin' && $password === 'password123') {
$_SESSION['loggedin'] = true;
header('Location: dashboard.php');
exit;
} else {
echo 'Invalid username or password';
}
}
?>
<form method="post" action="">
<input type="text" name="username" placeholder="Username" required><br>
<input type="password" name="password" placeholder="Password" required><br>
<button type="submit">Login</button>
</form>
Related Questions
- How can PHP and JavaScript be effectively integrated for form validation and submission?
- How can PHP beginners troubleshoot issues like links not redirecting correctly on an online server, and what best practices should be followed when seeking help on forums or online communities?
- What is the significance of resetting the file pointer after reading the file in PHP?