# Strange PHP Session Problem

**URL:** <https://forum.kirupa.com/t/strange-php-session-problem/245731>\
**Category:** web dev\
**Created:** [December 3, 2007, 2:04pm UTC](https://forum.kirupa.com/t/strange-php-session-problem/245731 "2007-12-03T14:04:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![NathanZachary](https://avatars.discourse-cdn.com/v4/letter/n/f475e1/32.png) [@NathanZachary](https://forum.kirupa.com/u/NathanZachary)\
**Post date:** [December 3, 2007, 2:04pm UTC](https://forum.kirupa.com/t/strange-php-session-problem/245731/1 "2007-12-03T14:04:58Z")

</div>

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)

```php
$UserName=$_POST['UserName'];
$Password=$_POST['Password'];
$result=mysql_query("SELECT * FROM register WHERE UserName= '$UserName';");
$row=mysql_fetch_array($result);

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

session_start();
$_SESSION['User']= $UserName;
$_SESSION['ID']= $row['ID'];

header("location:http://localhost/forum/users/user.php");

}else{

header("location:http://localhost/forum/common/login.php?action=LoginError003datamismatch");

}

```

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

```php

<html>
<body>
<?php

echo $_SESSION['User'];

?>
</body>
</html>

```

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
