//昨天寫(xiě)的思路不對(duì),重新寫(xiě)....
/**
*檢查IP是否重復(fù)登錄多次
*/
public function check_ip(){
//獲取ip
$login_ip=$_SERVER["REMOTE_ADDR"];
$login_time=date("Y-m-d",time());
if(Cache::get('cache_login_data')==false){
//如果ip換成為false,那么創(chuàng)建一個(gè)緩存,并賦值第一個(gè)
$login_data[0]=['login_ip'=>$login_ip,'login_time'=>$login_time];
Cache::set('cache_login_data',$login_data);
}else{
//如果有cache,那么將這條數(shù)據(jù)加入到緩存中最后一條去
$cache_login_data=Cache::get('cache_login_data');
$count=0;
foreach($cache_login_dataas$k=>$v){
//如果當(dāng)前緩存中的值含有當(dāng)前ip和時(shí)間,那么計(jì)算當(dāng)前時(shí)間內(nèi)登錄次數(shù)
if($v['login_time']==$login_time&&$v['login_ip']==$login_ip){
$count++;
if($count>10){
//當(dāng)前ip登錄超過(guò)10次
$this->error("你登錄超過(guò)了10次,請(qǐng)不要再來(lái)登了...","Login/index");
}else{
//當(dāng)前時(shí)間內(nèi)有該IP登陸過(guò),但是沒(méi)有超過(guò)10次
$cache_login_data[count($cache_login_data)+1]=['login_ip'=>$login_ip,'login_time'=>$login_time];
Cache::set('cache_login_data',$cache_login_data);
}
}else{
//當(dāng)前時(shí)間內(nèi),該IP沒(méi)有登陸過(guò)
$cache_login_data[count($cache_login_data)+1]=['login_ip'=>$login_ip,'login_time'=>$login_time];
Cache::set('cache_login_data',$cache_login_data);
}
}
}
}