Now on all your pages you are passing along the session variable (Same concept with cookies I believe you need ob_start(); on top of every page if you use it ...I haven't worked with cookies much so I think it's ob_start()

Remember session_start(); at the TOP very top of every page. Then in middle of your pages you can do

Code:

<?php echo "Hello ".$_SESSION['username']."!"; ?>

And that'll display Hello USERNAME! And it'll mean they are logged in.

syntax101

thank u so much. i forgot t put the session start thats why i cannot display the username. so in every page you have to session start right?

kv

syntax101 wrote:

so in every page you have to session start right?

Yes otherwise you will not be able to use session variables from previous invocations.

What I suggest you is to have a file, say, authenticate.php, which contains code to authenticate if the user has logged in. It will also contain session_start. ex: