<?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); } } ?>