i have this simple question please.
I have this part of code which sets my session:
if($count==1){
// Register $myusername, $mypassword and redirect to file "admin.php"
session_register("admin");
session_register("password");
$_SESSION['name']= $myusername;
header("location:index.php");
}
And this is what i put in every file to protect it :
<?php
session_start(); //Start the session
define(ADMIN,$_SESSION['name']); //Get the user name from the previously registered super global variable
if(isset($_SESSION['admin'])){//If session not registered
header("location:login.php"); // Redirect to login.php page
}
else //Continue to current page
header( 'Content-Type: text/html; charset=utf-8' );
?>
I need to change the session name because i already have one like this.
Thanks
First of all, stop to use the session_register() function, it has been DEPRECATED and REMOVED as of PHP 5.4.0.
You should write the first part like below:
Analysing the second part, the
if/elselogic is inverted. This is the right logic.