Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use time to count how many seconds you logged in

Tags:

php

time

mysql

Let's say I have a user/pass to enter and once it's entered another page will be redirected and in that profile page will show a line sayingi you have been staying here for xxx seconds.

I am new in PHP MySQL I have website called itube.one I already created login/register system. I need some tutorials or sothing showing exactly what i want i cant fit this script to my site I am using PHP 5.6

session_start();
if(!(isset($_SESSION["username"])))
{
    header("location: index.php");
}
else
{
    echo "Welcome " . $_SESSION["username"] . "<br/>";
    echo "You have been logged in for " . $_SESSION["timeLogged"] . " seconds.";
}
like image 759
beqa gotoshia Avatar asked May 31 '26 17:05

beqa gotoshia


1 Answers

Looking at your code I assume that in your login code you are setting this:

$_SESSION['timeLogged'] = time();

Then in your subsequent pages you can use this:

$timeSinceLogged = time() - $_SESSION["timeLogged"];
echo "You have been logged in for " . $timeSinceLogged . " seconds.";
like image 71
davidethell Avatar answered Jun 03 '26 05:06

davidethell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!