I have a session code here that i want to redirect the all users if the session username is not equal to administrator..but my code is not working..can anyone know whats the problem? Please
code here:
<?php
session_start();
if(isset($_SESSION['username'])!='administrator'){
header('Location: ../index.php');
}
?>
The return value of isset will never equal 'administrator'. Try this:
if (!isset($_SESSION['username']) || ($_SESSION['username'] != 'administrator'))
isset will only return true or false. If you want to check that it exists AND the value is not "administrator", something like:
<?php
session_start();
if(!empty($_SESSION['username']) && $_SESSION['username'] !='administrator'){
header('Location: ../index.php');
}
?>