www.webdeveloper.com
Results 1 to 5 of 5

Thread: how to display last visited user's date and time in header of the webpage??

  1. #1
    Join Date
    Jun 2013
    Posts
    3

    how to display last visited user's date and time in header of the webpage??

    how to display last visited user's date and time in header of the webpage??

  2. #2
    Join Date
    Dec 2011
    Posts
    159
    Maybe a short code that would write to a cookie every minute, of course once the user closes out the page, the cookie can no longer be written to, hence a last visited time stamp?

  3. #3
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    This is a simple task... you need to add the columns to your database entering time of login and holding a place for the last login.

    then when authenticating someone who logs in, you would call there username to display add last login date to the query and store it in the session.

    then make a place for it in your header and echo it.

    it would look like this..

    this is the file which authenticates and stores the session variables when someone logs in. im obviously posting the section which would execute on a successful login.

    Code:
     	if ($username==$dbusername&&$password==$dbpassword)
    	{
    		echo("Successful Login!");
    		session_start();
    		$_SESSION['username'] = $username;
                    $_SESSION['LastLoginDate'] = $LastLoginDate;
                    header("Location:UserHomePage.php");
    then you would simple echo the information you just stored in the session in the page that you send them to when they log in. in this example is it UserHomePage.php
    notice we session start and then create security so if there is no session username stored we redirect to index.php. but since there is a username stored it shows in the title of the page username 's Dashboard.

    then to echo out the LastLoginDate in this example we do the same thing anywhere on the page. in this example im just using echo to call out the LastLoginDate in the middle of the page


    Code:
    <?php
    session_start();
    if (!isset($_SESSION['username'])){
    header("Location:index.php");
    exit();
    }
    ?>
    
      <?php
      if (isset($_SESSION['username'])){
    echo "<b>welcome</b>";
    }else{
    header("Location:index.php");} ?>
    
    <html lang="en">
        <head>
            <title><?php echo $_SESSION['username']; ?>'s Dashboard</title>
         
    <link rel="stylesheet" href="css/layout.css" type="text/css" media="all">
    </head>
    
    <body>
    
    <div class="container">
    
    <?php echo $_SESSION['LastLoginDate']; ?>
    
    <a href="logout.php">Logout</a>
    </div>
        <div class="navigate">
       <?php include 'nav.php' ?>
        </div>
    </body>
    </html>

  4. #4
    Join Date
    Jun 2013
    Posts
    3
    thanx a lot ..... this'll be very helpful ...thnxxx

  5. #5
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    If you have any questions or need more examples just ask

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles