PHP Authenticate user for each page of website
I'm developing a website, where in most of pages user need to log in to
view pages of website. What is the best way to check if user is logged in
or not, and if not redirect it to log-in page.
currently I'm using following code to do that.
if(!isset($_SESSION["username"])) //I set the session when user log in
and destroy when user logout
header("location: login.php");
There are lot of pages and I put this code in every page. It also works well.
I want to know is there any other batter way to do this? Or what I'm doing
is good way? and I don't need to change anything.
No comments:
Post a Comment