PHP How to add a line with the time and date of the user's last login? login.php

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

PHP How to add a line with the time and date of the user's last login? login.php

Post by answerhappygod »

PHP How to add a line with thetime and date of the user'slast login?
login.php
<?php
define('TITLE', 'User Login');
print '<h2>Login Form</h2>
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if ((!empty($_POST['email']))&& (!empty($_POST['password']))) {
if((strtolower($_POST['email']) =='[email protected]')&&($_POST['password'] == 'test')){
session_start();
$_SESSION['email'] = $_POST['email'];
$_SESSION['loggedin'] = time();
$_SESSION['last'] =time(); //???????????????????????????????????????
ob_end_clean();
header('Location: menu.php');
exit();
}
}
}
else {
print '<form action="login.php"method ="post" class="form--inline">
<p><labelfor="email">Email Address:</label><input type="email"name="email" size="20"></p>
<p><labelfor="password">Password:</label><input type="password"name="password" size="20"></p>
<p><input type="submit"name="submit" value="Log In" class="button--pill"></p>
</form>';
}
?>
menu.php
<?php
session_start();
define('TITLE', 'Our Menu');
?>
<?php
date_default_timezone_set('America/Toronto');
print '<p><b>Hello,'.$_SESSION['email'].'</b></p>';
print '<p>You have logged at:<b>'.date('g:i a',$_SESSION['loggedin']).'</b></p>';
print '<p>You last logged at:<b>'.date('g:i a',$_SESSION['last']).'</b></p>';
//???????????????????????????????????????
?>
lgout.php
<?php
session_start();
$_SESSION = [];
session_destroy();
define('TITLE', 'Logout');
?>
<p>You have now been out.</p>
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply