There are pages index.php, catalog.php and item.php. How to close access to them to an unauthorized user on the site? (without using javascript)
What would the user who did not log in, tossed on the login page or on the page with an error.
Thank you in advance!
(If it is not difficult, please describe the specific method)
|
1 answer
After successful authorization, write, for example, the user ID in the session:
$_SESSION['user_id'] = $assoc['id']; On the pages check the existence of the session
if(!isset($_SESSION['user_id'])) { header("Location: /login"); exit; } After logging out, delete the session
unset($_SESSION['user_id']); By writing the ID in the session, you can identify the user on any page.
- Thank you for setting a good example and giving directions where to dig! - HapochkaV pm
|
<?php if(!isAuth()) {header('/login.php');} else {.....}?>in general, something like this. - Vladimir Klykov