Q:

php session is not redirecting

I am working with php session as one of my experiment. Trying to learn by developing a script. But I have stacked. I am not quire sure why the php session isn't working.My log in page redirecting my page when i submitting correct email address and password. I am trying to skip log in page if session is set. But its not redirecting. here is the code. Even there has no error log output. So i became so confused what wrong with my code. I am looking for expert suggestion on my experiment. 
<?php
session_start();
#Working With Session
if (isset($_SESSION['UserId'])) {
    # code...
    header('location:/management/index.php');
exit();
}
require_once("../configuration.php");
#Veriable collected From Login Panel
$Submitted_Email_Address=$_POST['email'];
$Submitted_Password=$_POST['password'];
$encrypt_Submitted_Password=md5($Submitted_Password);

#Lets gather Data From MySql Database
$con=new mysqli($hostname,$dbusername,$dbpass,$dbname);
if (mysqli_connect_errno($con)) {
    die('The connection to the database could not be established.');
}
$query="SELECT * FROM users WHERE Email_Address='$Submitted_Email_Address'";
$result=$con->query($query);
$row=$result->fetch_array();
$SQL_Password = $row['Password'];
#LookUp Mysql Database to Get username/user id to store in session
$SQL_UserID=$row['id'];
$SQL_UserName=$row['username'];
$SQL_FirstName=$row['First_Name'];
$SQL_LastName=$row['Last_Name'];
$SQL_Role=$row['Role'];
if ($encrypt_Submitted_Password!=$SQL_Password) {
       echo "Please check your email address and password again";
}
elseif ($encrypt_Submitted_Password == $SQL_Password) {
$_SESSION['UserID']=$GLOBAL['SQL_UserID'];
$_SESSION['UserName']=$GLOBAL['SQL_UserName'];
$_SESSION['FirstName']=$GLOBAL['SQL_FirstName'];
$_SESSION['LastName']=$GLOBAL['SQL_LastName'];
$_SESSION['Role']=$GLOBAL['SQL_Role'];
header('location:/management/index.php');
}

#Lets CLose All The MySql Connection
$result->free();
$con->close();
?> 

After that i tried to see if the session is not set then redirect the page. but its not redirecting. I tried the following code to check if the session is not set let redirect the page. but not redirecting
session_start();
    #Working With Session
    if (!isset($_SESSION['UserId'])) {
        # code...
        header('location:/management/index.php');
    exit();
    }

A:

You need to change your header call:
header('Location: /management/index.php'); // notice capitalization and spacing; they matter.

A:

I guess you are missing something so silly. your code seems that its a php file which gather email address and password from a login page and validate it and then redirect it two another page. 
I think your login page (might be login.html, access.html) is not redirecting. So your should put this following php code block in the login page. not here in the login.php which is only used to validate the inputed data. Happy coding and keep your mind calm. :)
and you have to use 'UserID' not 'UserId'
session_start();
#Working With Session
if (isset($_SESSION['UserID'])) {
    # code...
    header('location:/management/index.php');
exit();
}

