What are the benefits of combining sessions with cookies in a PHP login script?
Combining sessions with cookies in a PHP login script can provide added security and convenience for users. Sessions store user data on the server side, while cookies store data on the client side. By using both, you can maintain user sessions even if they close their browser and provide a seamless login experience for returning users.
// Start session
session_start();
// Set session variables
$_SESSION['user_id'] = $user_id;
// Set cookie to remember user
setcookie('user_id', $user_id, time() + (86400 * 30), "/"); // 30 days expiration