How can a PHP script be used to limit a user to accessing a page only once?
To limit a user to accessing a page only once, you can use a session variable to track whether the user has already visited the page. If the session variable is set, the user will be redirected away from the page. If not, the session variable will be set to prevent further access.
<?php
session_start();
if(isset($_SESSION['visited'])) {
header('Location: another_page.php');
exit();
}
$_SESSION['visited'] = true;
?>
Keywords
Related Questions
- How can PHP developers ensure that number formatting functions in templates do not mistakenly replace all separators instead of specific ones?
- What are some common methods for generating unique filenames for uploaded files in PHP?
- How can PHP beginners differentiate between PHP and MySQL syntax to prevent errors in database operations?