Is using a session ID a better alternative to storing login data in cookies?
Using a session ID is generally considered a more secure alternative to storing login data in cookies. Session IDs are stored on the server side and are harder for malicious users to access compared to cookies, which are stored on the client side. By using session IDs, sensitive login data is kept secure and protected from potential security threats.
<?php
// Start a session
session_start();
// Generate a unique session ID
$session_id = session_create_id();
// Store the session ID in a session variable
$_SESSION['session_id'] = $session_id;
// Use the session ID for authentication
// Additional login logic here
// Destroy the session when the user logs out
session_destroy();
?>