如何在注销PHP脚本上输入时间和日期
我想知道是否有一种方法可以将日期和时间放在PHP脚本上,这样当用户注销时,它会显示类似于您在2016年4月19日上午11:00注销的如何在注销PHP脚本上输入时间和日期,php,Php,我想知道是否有一种方法可以将日期和时间放在PHP脚本上,这样当用户注销时,它会显示类似于您在2016年4月19日上午11:00注销的的内容。我的PHP脚本是 <?php // include function files for this application require_once('bookmark_fns.php'); session_start(); $old_user = $_SESSION['valid_user']; // store to test if they
的内容。我的PHP
脚本是
<?php
// include function files for this application
require_once('bookmark_fns.php');
session_start();
$old_user = $_SESSION['valid_user'];
// store to test if they *were* logged in
unset($_SESSION['valid_user']);
$result_dest = session_destroy();
// start output html
do_html_header('Logging Out');
if (!empty($old_user)) {
if ($result_dest) {
// if they were logged in and are now logged out
echo 'Logged out.<br />';
do_html_url('login.php', 'Login');
} else {
// they were logged in and could not be logged out
echo 'Could not log you out.<br />';
}
} else {
// if they weren't logged in but came to this page somehow
echo 'You were not logged in, and so have not been logged out.<br />';
do_html_url('login.php', 'Login');
}
do_html_footer();
?>
有了功能,它很容易:
$date = date("d/m/Y");
$time = date("H:iA");
echo "You logged out on the $date at $time";
// return You logged out on the 19/04/2016 at 02:59AM
只有一行,您没有指定要将其插入数据库,如果指定了,则需要在echo语句的相同位置使用insert语句,使用相同的技术获取当前时间
if (!empty($old_user)) {
if ($result_dest) {
// if they were logged in and are now logged out
echo 'Logged out.<br />';
$date = date("Y-m-d H:i:s");
//Displays message, of the current datetime.
echo "You logged out at: $date";
do_html_url('login.php', 'Login');
} else {
// they were logged in and could not be logged out
echo 'Could not log you out.<br />';
}
if(!empty($old_user)){
如果($result\u dest){
//如果他们已登录并且现在已注销
echo“已注销。
”;
$date=日期(“Y-m-d H:i:s”);
//显示当前日期时间的消息。
echo“您在:$date注销”;
do_html_url('login.php','login');
}否则{
//他们已登录,无法注销
echo“无法将您注销。
”;
}
我认为您会发现一些有用的示例。在用户注销时,在会话\u销毁之前,启动一个查询,插入日期和时间
将日期时间写入数据库或文件。如果您不打算将此信息保存到数据库中,只需沿日期时间日期(“Y-m-d H:I:s”)回显消息即可。