简体   繁体   English

如何将时间和日期放在注销 PHP 脚本上

[英]How to put the time and date on a logout PHP script

I'm wondering if there's a way of putting the date and time on a PHP script so that when a user logs out, it displays something along the lines of You logged out on the 19/04/2016 at 11:00AM .我想知道是否有一种方法可以将日期和时间放在 PHP 脚本上,以便当用户注销时,它会显示一些内容,类似于You logged out on the 19/04/2016 at 11:00AM The PHP script that I have is我拥有的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();

?>

With date function it's easy :使用日期功能很容易:

$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

Just one simple line, you didn't specify that you wanted to insert this into the database, if you did, you'd need to use an insert statement in the same place of the echo statement, using the same technique to grab the current time.只是一个简单的行,您没有指定要将其插入到数据库中,如果您这样做了,则需要在 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 />';
}

These examples I think you will find helpful.这些例子我想你会觉得很有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM