At present I'm using $_SESSION['UserName'] to create and store the login details. But I'm not able to access this session variable. Is there any way for the website to remember these details? $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "LoginOK.php" session_start(); session_register("myusername"); session_register("mypassword"); $_SESSION['loginname'] = $myusername; //echo $_session['loginname']; header("location:index.php"); } PHP: I'm using <?php echo $_session['loginname']; in index.php. Is there anything wrong with the code?
Did you place session_start() on all pages where the session should run? And don't use session_register(), it's deprecated. Do it just like you do below in your code: $_SESSION['loginname'] = $myusername; PHP: Where does $myusername come from? Maybe the variable just doesn't contain what you expect, and therefore it's not working...
You also need to declare session_start() as the very first line of code on every page. It needs to be called before any headers are sent, otherwise it will fail.
There are no problems with you code, everything seems fine. However, I would do it using database (more professional). Give the user a unique session ID which is stored in the database and use it to retrieve the user info on each page load. Peace,