I\'m writing a user login system, and I (like so many others) am having a problem with my sessions.
Here\'s the pointer from the login script when the inputs are validat
Have you tried:
print_r($_SESSION);
to examine the contents of the session?
use
ob_start(); @session_start();
on the top of the both page
First of all, please enable debugging:
error_reporting(E_ALL);
ini_set('display_errors', '1');
Second, session_start() needs to be at the top of the page. So the line you wrote;
You are logged in as: <?php echo session_start();$_SESSION['id']; ?>
will never work.
The following line needs to be on top of the page, before any HTML etc.
<?php
session_start();
$id=$_SESSION['id'];
?>
You're most likely running into output buffering, which is why it sometimes works and other times it does not. Generally speaking, stick to starting the session before any output is generated, you'll find your code works better.
Make sure you're calling session_start()
before you output anything on the page. The standard cookie-based sessions require some header information to be exchanged, which must be done before you send any content.