-2

I made a login system, how do I make it show the username after login, so it goes like on the main login screen -> database check -> success page. On this success page how do I make it show the username, that was registered? I have only added

<?php
session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
}
?>

On the 3rd page which is the success page, I need it to show the username that has logged on and other user information from the table.

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • Go see this question: http://stackoverflow.com/questions/14208369/retrieve-data-from-mysql-using-php – freddy Dec 06 '13 at 05:47
  • After the login check the username is stored on the session – Vinod VT Dec 06 '13 at 05:47
  • Once the session variable is stored, you can read it on any page with a little php like - $userid = $_SESSION['useridentifier']. – TimSPQR Dec 06 '13 at 05:50

4 Answers4

1

you need to store the username in the session variable then after successful login display it. you can use isset() to serve that purpose to check whether the session variable is set or not.

<?php
    session_start();
    echo $_SESSION['username'];
?>
R R
  • 2,999
  • 2
  • 24
  • 42
0

Something like this will do

<?php
session_start();
if(isset($_SESSION['myusername'])){
    echo "Welcome ".$_SESSION['myusername'];
}
else
{
   header("location:main_login.php");
}
?>

And don't use session_is_registered() as it is Deprecated.

Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
0

Once you successfully logged in then store the username in the session variable. On the page first check whether session is set then show the username else redirect the user to login page.

 <?php
session_start();
if(isset($_SESSION['myusername']) && $_SESSION['myusername'] != ''){
      echo $_SESSION['myusername'];
}else{
      header("location:main_login.php");
}
?>
0
<?php
     session_start();
     //if using post method in login it is better to check if $_POST is set
     $username = $_POST['myusername'];
     if(isset($_POST['myusername'])){
      if(!empty($username)){
       if(isset($_SESSION['myusername'])){
        echo $_SESSION['myusername'];
       }
      }
     }
 ?>

You can provide security by checking if your login details are not empty.

shubhraj
  • 391
  • 3
  • 12