What tools or methods can PHP developers use to set and manage extra cookies for specific actions, such as requiring all users to log in again?
To set and manage extra cookies for specific actions in PHP, developers can use the setcookie() function to create new cookies with specific settings such as expiration time, path, and domain. To require all users to log in again, developers can set a new cookie with a short expiration time and check for its presence in the user authentication process.
// Set a new cookie for requiring users to log in again
setcookie('reauth', '1', time() + 60, '/');
// Check for the presence of the 'reauth' cookie in the authentication process
if (!isset($_COOKIE['reauth'])) {
// Redirect the user to the login page
header('Location: login.php');
exit;
}
Related questions
-
PHP data elements arrays
-
PHP array_search one-dimensional array
-
server settings PHP.ini configurations memory size