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

时间:2016-04-19 09:54:29

标签: php

我想知道是否有一种方法可以将日期和时间放在PHP脚本上,这样当用户退出时,它会显示You logged out on the 19/04/2016 at 11:00AM行的内容。我拥有的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();

?>

2 个答案:

答案 0 :(得分:1)

使用date功能很简单:

$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

答案 1 :(得分:0)

只是一个简单的行,你没有指定你想将它插入到数据库中,如果你这样做,你需要在echo语句的同一个地方使用一个insert语句,使用相同的技术抓住当前时间。

r=['  200      200      200      200    ', '    3,50     3,50     3,50     3,50 ', ' 1000     1000     1000     1000    ', '1.000    1.000    1.000    1.000    ']

import re
I = []
p = re.compile(r"^\s*(\S)|\s{2,}(\S)")
for n in range(0,len(r)):
    itemp = []
    for m in p.finditer(r[n]):
        if (m.group(1)):              # Check if Group 1 matched
            itemp.append(m.start(1))  # Then get its start pos
        else:                         # Then Group 2 matched
            itemp.append(m.start(2))  # Get its start pos
    I.append(itemp)
print(I)

These示例我认为您会发现有用。