created a file called session.php
<?php ob_start(); session_start();
than we need to include a file on every page that we want to protect in this way
<?php include 'session.php'; var_dump($_SESSION); if(isset($_SESSION) ){ if(!$_SESSION['name']=='admin'){ header("Location:login.html?id=access_forbidde"); } }else{ header("Location:viewall.php?id=access_forbidde"); }
otherwise, you must indicate each page separately on this page.
& logout contains
<?php include 'session.php'; $_SESSION=array(); setcookie(session_name(),"",time()-3600); session_destroy(); header("Location: login.html?id=logout_successful"); ?>
thanks to PHP_Noob for his help. and I did it in a week
source share