Strange PHP Session Problem

This is the first time I’ve worked with PHP Sessions, and I must say, that this is strange. Sometimes it works, and sometimes not.

What you see below, is a fragment of my LogIn script, where upon successful sign in, I would like to start a session, and continue to the users page (Members Area)

$result=mysql_query("SELECT * FROM register WHERE UserName= '$UserName';");

if($row['UserName'] == $UserName && $row['Password'] == $Password){

$_SESSION['User']= $UserName;
$_SESSION['ID']= $row['ID'];





On the Users page, I would like to check if the session has started, and get UserName and ID.


echo $_SESSION['User'];


The problem is. The Username never shows up. I have done everything. Rearrangement and spellcheck. What have i missed?

Edit: As the Localhost I use XAMPP