html - How to check if the session is set in header.php -


i have more 30 pages , 20 of them has seen user check if user logged in using if statement.

if($_session['username']){ //display page (all html code here.) }else{  header("location: index.php"); } 

the question don't wanna type same thing every page. so, thought can type part in header.php

if($_session['username']){ 

and part in footer.php

}else{  header("location: index.php"); } 

but doesn't work that. wonder can do? efficient way?

in file:
if(!$_session['username']){ header("location: index.php"); }

and everywhere need it: require("myfile.php");


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -