飞狐爷

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
<?php
$f = new myfile();
$e = new myerr();

if(!$f->isFile()){
    $f->createFile();
}
if(isset($_GET['newtime']) && !empty($_GET['newtime'])){
    $_GET['newtime'] = strtotime($_GET['newtime']);
    if(!($_GET['newtime'])){
        $e->setErr('日期格式错误');
        $e->show();
    }
    $f->editFileData($_GET['newtime']);
}
echo date('Y-m-d',$f->readFile());

if($f->isExpired()){
    $e->setErr('已过期,请续费。');
    $e->show();
}

class myerr{
    public $errtxt = array();
    
    public function __construct(){
        
    }
    public function setErr($str=''){
        $this->errtxt[] = $str;
    }
    public function show(){
        echo '<ul>';
        foreach($this->errtxt as $k=>$v){
            echo '<li>'.$v.'</li>';
        }
        echo '</ul>';    
        exit; 
    }
    public function clearErr(){
        $this->errtxt = array();
    }
}
class myfile{
    public $filev = 'data.txt';
    public $fp = '';
    public $cont = '';
    
    public function __construct(){
        
    }
    public function createFile($newtime=''){
        $this->fp = fopen($this->filev,'w+');
        if($newtime)
            fwrite($this->fp, $newtime);
        else
            fwrite($this->fp, time()+3600*24*365);
        fclose($this->fp);
    }
    public function delFile(){
        unlink($this->filev);
    }
    public function readFile(){
        $this->cont = file_get_contents($this->filev);
        return $this->cont;
    }
    public function isExpired(){
        if(time() > $this->readFile()){
            return true;
        }
        return false;
    }
    public function isFile(){
        return file_exists($this->filev);
    }
    public function editFileData($mydata=''){
        $this->delFile();
        $this->createFile($mydata);
    }
}
?>

 

posted on 2018-03-21 15:12  飞狐爷  阅读(169)  评论(0编辑  收藏  举报