Wordpress PHP $ _SESSION

I am writing a login page for my site using PHP. I developed it on my local computer and it works with no issues however I have put it on Wordpress and now the page will not login due to the $_SESSION not having the key 'UserName'.

I investigated the issue and found that the $_SESSION data is not saving/setting due to when I print_r($_SESSION) it returns Array(). How do I use $_SESSION on Wordpress?

this is at the top of my index.php page

if (!session_id()) 
session_start();

if (!isset($_SESSION['UserName'])) {
    header("Location: login.php");
}

And on login.php (what is setting the infomation)

if (!session_id()) 
session_start();

$_SESSION['UserID'] = $row['UserID'];
$_SESSION['UserName'] = $_POST['user']; // Leave decrypted
$_SESSION['Password'] = $pass; // Leave encrypted

I assume wordpress does it differently. Could someone please explain.