Session in php are not enough clear to me

Posted by Lulzim on Stack Overflow See other posts from Stack Overflow or by Lulzim
Published on 2012-07-06T08:21:38Z Indexed on 2012/07/06 9:15 UTC
Read the original article Hit count: 167

Filed under:
|

I find sessions in php kind of confusing, can anybody of you explain those to me. I have an example which is not working in my case: I register sessions this way, would you please tell me is this the right way of registering sessions

 //this is the page from where i register myusername in sessions
if($count==1){
    session_start();
    $_SESSION['myusername'] = $_POST['myusername']; 
    include("enterpincover.php");
}
else {
    echo "Wrong Pin";
}

here i check first whether the username is registered in sessions in oder to open his account , otherwise open again login.

It works, if user is not loged in, it will show login page which is right, if user is loged it shows welcome message but not the Welcome the name of the user as I want. for ex: Welcome David

<?php
session_start();
if(isset($_SESSION['myusername']))
{
    echo 'Welcome '.$_SESSION['myusername']; 
}
else
{
    include("leftmodules.php");
    include("rightmodules.php");
    include("login.php");
}
?>

© Stack Overflow or respective owner

Related posts about php

Related posts about session