网上没有找到简单的代码,这是自己摸索出来的。若有更好的方法,欢迎提出来!
error_reporting(0);
$conn=mysql_connect(“localhost:3306″,”root”,””);
if(!$conn){
die(“连接失败”.mysql_errno());
}
mysql_query(“set names utf8”,$conn)or die (mysql_errno());
mysql_select_db(“shop”,$conn) or die (mysql_errno());
$username=$_SESSION[‘adminName’];
$check = mysql_query(“select * from user where username=’$username’ order by id desc limit 1”);
if($info = mysql_fetch_array($check)){
$mydate = $info[‘time’];//从数据库读取上次签到时间
}
//上面代码可以用$mydate=”2015-9-16″;进行测试
$mydate=date(‘Y-m-d’,strtotime($mydate));//转换成不带时间只带日期的
$days=abs((time()-strtotime($mydate))/86400);//用当前时间-上次签到日期
if($days>1){
echo “请签到”;
}else{
echo “已签到”;
}
?>