How can the session.use_only_cookies setting affect the login functionality in PHP scripts?
When the session.use_only_cookies setting is enabled in PHP, it ensures that sessions are only maintained using cookies and not passed through URLs. This can affect login functionality if the script relies on passing session IDs through URLs for authentication. To solve this issue, you can modify the script to use cookies for session management instead.
// Enable session.use_only_cookies setting
ini_set('session.use_only_cookies', 1);
// Start the session
session_start();
// Check login credentials
if ($_POST['username'] === 'admin' && $_POST['password'] === 'password') {
// Set session variables
$_SESSION['loggedin'] = true;
$_SESSION['username'] = $_POST['username'];
// Redirect to dashboard
header('Location: dashboard.php');
exit();
} else {
echo 'Invalid username or password';
}