页首Html代码

//PHP商品倒计时  
date_default_timezone_set("Asia/shanghai");//地区  
   
//配置每天的活动时间段  
$starttimestr = "2013-09-18 08:00:00";  
$endtimestr = "2013-09-18 18:00:00";  
   
$starttime = strtotime($starttimestr);  
$endtime = strtotime($endtimestr);  
$nowtime = time();  
if ($nowtime<$starttime){  
die("活动还没开始,活动时间是:{$starttimestr}至{$endtimestr}");  
}  
if ($endtime>=$nowtime){  
$lefttime = $endtime-$nowtime; //实际剩下的时间(秒)  
 }else{  
 $lefttime=0;  
 die("活动已经结束!");  
}  
  
?>  
  
   
<script language="JavaScript">  
var runtimes = 0;  
function GetRTime(){  
var nMS = <?php echo $lefttime; ?>*1000-runtimes*1000;  
if (nMS>=0){  
var nD=Math.floor(nMS/(1000*60*60*24))%24;  
var nH=Math.floor(nMS/(1000*60*60))%24;  
var nM=Math.floor(nMS/(1000*60)) % 60;  
var nS=Math.floor(nMS/1000) % 60;  
document.getElementById("RemainD").innerHTML=nD;  
document.getElementById("RemainH").innerHTML=nH;  
document.getElementById("RemainM").innerHTML=nM;  
document.getElementById("RemainS").innerHTML=nS;  
if(nMS==5*60*1000)  
{  
alert("还有最后五分钟!");  
}  
runtimes++;  
setTimeout("GetRTime()",1000);  
}  
}  
window.onload=GetRTime;  
</script>  
   
<h4>距离活动结束还有 <strong id="RemainD">XX</strong>天 <strong id="RemainH">XX</strong>小时 <strong id="RemainM">XX</strong>分钟 <strong id="RemainS">XX</strong>秒</h4>  

php实现当前用户在线人数

<?php  
/** 
*@ Date         2013.04.07 
*@ Author      网络剑客 
*@ Blog         http://blog.csdn.net/dongsg11200 
*/  
$user_online = "count.php"; //保存人数的文件  
touch($user_online);//如果没有此文件,则创建  
$timeout = 30;//30秒内没动作者,认为掉线  
$user_arr = file_get_contents($user_online);  
$user_arr = explode('#',rtrim($user_arr,'#'));print_r($user_arr);  
$temp = array();  
foreach($user_arr as $value){  
$user = explode(",",trim($value));  
if (($user[0] != getenv('REMOTE_ADDR')) && ($user[1] > time())) {//如果不是本用户IP并时间没有超时则放入到数组中  
array_push($temp,$user[0].",".$user[1]);  
}  
}  
array_push($temp,getenv('REMOTE_ADDR').",".(time() + ($timeout)).'#'); //保存本用户的信息  
$user_arr = implode("#",$temp);  
//写入文件  
$fp = fopen($user_online,"w");  
flock($fp,LOCK_EX); //flock() 不能在NFS以及其他的一些网络文件系统中正常工作  
fputs($fp,$user_arr);  
flock($fp,LOCK_UN);  
fclose($fp);  
echo "当前有".count($temp)."人在线";  
?>  

 

posted on 2015-02-10 15:25  西北阳仔2号  阅读(149)  评论(0编辑  收藏  举报
页脚Html代码