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)
$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.
<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