在网页中显示在线人数的代码
[quote color="success"]在线人数使用方法[/quote]
首先在主题文件里的functions.php里面最下面放入以下代码:
//在线人数
function online_users() {
$filename='online.txt'; //数据文件
$cookiename='Nanlon_OnLineCount'; //Cookie名称
$onlinetime=30; //在线有效时间
$online=file($filename);
$nowtime=$_SERVER['REQUEST_TIME'];
$nowonline=array();
foreach($online as $line){
$row=explode('|',$line);
$sesstime=trim($row[1]);
if(($nowtime - $sesstime)<=$onlinetime){
$nowonline[$row[0]]=$sesstime;
}
}
if(isset($_COOKIE[$cookiename])){
$uid=$_COOKIE[$cookiename];
}else{
$vid=0;
do{
$vid++;
$uid='U'.$vid;
}while(array_key_exists($uid,$nowonline));
setcookie($cookiename,$uid);
}
$nowonline[$uid]=$nowtime;
$total_online=count($nowonline);
if($fp=@fopen($filename,'w')){
if(flock($fp,LOCK_EX)){
rewind($fp);
foreach($nowonline as $fuid=>$ftime){
$fline=$fuid.'|'.$ftime."\n";
@fputs($fp,$fline);
}
flock($fp,LOCK_UN);
fclose($fp);
}
}
echo "$total_online";
}
然后在想要显示的地方放入以下代码即可,我的是放在页脚文件即footer.php
js 代码:<?php echo online_users() ?>
[quote color="warning"]运行时间代码使用方法[/quote]
1.本站已稳定运行了多少天的实现:
直接把下面代码复制到后台你想添加的位置即可。
本站已稳定运行了
js 代码:<strong><script language= "JavaScript" type= "text/javascript" >
var urodz= new Date ( "9/25/2015" );
var now = new Date ();
var ile = now.getTime() - urodz.getTime();
var dni = Math. floor (ile / (1000 * 60 * 60 * 24));
document.write(+dni)
</script>
</strong>天
下面这个是彩色的运行时间代码:
js 代码:<div style="text-align:center;font-size:10px" class="bg-white p-4 text-center">站点已稳定运行:<SPAN id=span_dt_dt
style="color: #2F889A;display: inline-block;"></SPAN><script language=javascript>function show_date_time() {
window.setTimeout("show_date_time()", 1000);
BirthDay = new Date("1/16/2022 00:00:01");
today = new Date();
timeold = (today.getTime() - BirthDay.getTime());
sectimeold = timeold / 1000
secondsold = Math.floor(sectimeold);
msPerDay = 24 * 60 * 60 * 1000
e_daysold = timeold / msPerDay
daysold = Math.floor(e_daysold);
e_hrsold = (e_daysold - daysold) * 24;
hrsold = Math.floor(e_hrsold);
e_minsold = (e_hrsold - hrsold) * 60;
minsold = Math.floor((e_hrsold - hrsold) * 60);
seconds = Math.floor((e_minsold - minsold) * 60);
span_dt_dt.innerHTML = '<font style=color:#C40000>' + daysold + '</font> 天 <font style=color:#C40000>' + hrsold + '</font> 时 <font style=color:#C40000>' + minsold + '</font> 分 <font style=color:#C40000>' + seconds + '</font> 秒';
}
show_date_time();</script>
2.年月日,星期几的实现:
直接把下面代码复制到后台你想添加的位置即可。
<script>
var mydate= new Date ()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate. getDate ()
if (daym<10)
daym= "0" +daym
var dayarray= new Array( "星期天" , "星期一" , "星期二" , "星期三" , "星期四" , "星期五" , "星期六" )
var montharray= new Array( "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "10" , "11" , "12" )
document.write(year+ "年" +montharray[month]+ "月" +daym+ "日" + " " +dayarray[day])
</script>
[quote color="success"]侧边栏添加当前时间[/quote]
方法
将以下代码放置在 sidebar.php 文件中合适的位置。
js 代码:<section id="sidebar-current-time" class="bg-white dark:bg-black dark:bg-opacity-20 card card-bordered rounded border border-gray-900/10 relative mb-4">
<div class="mx-4 py-2 my-2 flex items-center border-b border-gray-900/10">
<svg class="w-5 h-5 mr-1" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8937" width="200" height="200">
<path d="M512 514m-448 0a448 448 0 1 0 896 0 448 448 0 1 0-896 0Z" fill="#1afa29" p-id="8938" data-spm-anchor-id="a313x.7781069.0.i0" class="">
</path>
<path d="M512 512m-253.15 0a253.15 253.15 0 1 0 506.3 0 253.15 253.15 0 1 0-506.3 0Z" fill="#FFFFFF" p-id="8939">
</path>
<path d="M512 512m-203.07 0a203.07 203.07 0 1 0 406.14 0 203.07 203.07 0 1 0-406.14 0Z" fill="#1296db" p-id="8940" data-spm-anchor-id="a313x.7781069.0.i3" class="selected">
</path>
<path d="M622.12 497h-91.31a24.09 24.09 0 0 0-11.46-7.92V360.22a6 6 0 0 0-6-6h-2.81a6 6 0 0 0-6 6v128.93a24.06 24.06 0 1 0 26.19 38.08h91.49a6 6 0 0 0 6-6V503a6 6 0 0 0-6.1-6z" fill="#69B452" p-id="8941">
</path>
</svg>
<span>当前时间</span>
</div>
<div class="my-3">
<iframe src="https://www.whbblog.cn/currenttime/index.html" width="100%" height="110" frameborder="no">
</iframe>
</div>
</section>
[quote color="primary"]侧边栏添加和风天气[/quote]
方法
将以下代码放置在 sidebar.php 文件中合适的位置。
js 代码:<section data-id="sidebar-weather" class="bg-white dark:bg-black dark:bg-opacity-20 card card-bordered rounded border border-gray-900/10 relative mb-4">
<div id="he-plugin-standard">
</div>
<script>WIDGET = {
"CONFIG": {
"layout": "2",
"width": "238",
"height": "260",
"background": "1",
"dataColor": "FFFFFF",
"borderRadius": "5",
"key": "3180d3c43e524753ab8bcef69dba023a"
}
}</script>
<script src="https://widget.qweather.net/standard/static/js/he-standard-common.js?v=2.0">
</script>
</section>