在线状态和加载时间

2025-12-15 默认分类 11 0

在新版本移除在线状态和加载时间需要的可以自行添加

footer.php合适的位置加入

<p><?php _e('页面加载耗时'); ?><?php echo timer_stop();?> </p>
<p>💻️ <?php $this->author(); ?> <?php get_last_login(1); ?> 在线</p>

functions.php最后加入

/***
 * 在线状态
 */
function get_last_login($user){
    try {
        $user   = '1'; 
        $now    = time();
        $db     = Typecho_Db::get();
        $prefix = $db->getPrefix();
        $row = $db->fetchRow($db->select('activated')->from('table.users')->where('uid = ?', $user));
        if ($row) {
            echo Typecho_I18n::dateWord($row['activated'], $now);
        } else {
            echo '博主一直在这里';
        }
    } catch (Exception $e) {
        error_log('Error in get_last_login: ' . $e->getMessage());
        echo '博主一直在这里';
    }
}
/**
* 页面加载时间
*/
function timer_start() {
    global $timestart;
    $mtime = explode( ' ', microtime() );
    $timestart = $mtime[1] + $mtime[0];
    return true;
}
    timer_start();
function timer_stop( $display = 0, $precision = 3 ) {
    global $timestart, $timeend;
    $mtime = explode( ' ', microtime() );
    $timeend = $mtime[1] + $mtime[0];
    $timetotal = number_format( $timeend - $timestart, $precision );
    $r = $timetotal < 1 ? $timetotal * 1000 . " ms" : $timetotal . " s";
    if ( $display ) {
    echo $r;
    }
    return $r;
}
Typecho

相关文章

更新代码块测试
欢迎使用 Typecho