Issue
I'm trying to display a session start time on a page in this format
"Today you started work at: 00:00"
I found a session start time if statement but it doesn't seem to work for what I'm trying to do - either that or my syntax is wrong.
print "<td>Today you started work at: " ;
if (!isset($_SESSION['started'])){
$_SESSION['started'] = $_SERVER['REQUEST_TIME']
print $_SESSION['started'];
};
Solution
Never forget to add the ;
at the end of the line instruction.
$_SESSION['started'] = $_SERVER['REQUEST_TIME']
This code will only show a value if the session starts for the first time. because isset($_SESSION['started']))
will be false.
In this case, it will only display the timesamp of the the request time.
$_SERVER['REQUEST_TIME']
You must use the date()
function for time formatting
date("H:s",$_SESSION['started'])
Never forget also to add the session_start()
function before any printing.
Always close an open HTML tag
print "<td>Today you started work at: " ;
...
print "</td>" ;
Here is a correction:
session_start();
print "<td>Today you started work at: " ;
if (!isset($_SESSION['started'])){
$_SESSION['started'] = $_SERVER['REQUEST_TIME'];
}
print date("H:s",$_SESSION['started']);
print "</td>" ;
Answered By - le Mandarin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.