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>