php在某年月日之后过期(不受服务器本身时间设置影响)的代码分享

发布时间:2020-03-05编辑:脚本学堂
本文介绍下,一个可以让php代码在指定时间内过期的代码,且不受服务器本身的时间设置影响。有需要的朋友参考下。

代码如下:

<?php
/**
* php在指定时间内过期
* edit by www.jb200.com
*/
while(! ($dataFile = @fopen('http://www.jb200.com/6892.html', "r" )) ){
 sleep(2);
}
//$dataFile = fopen('data.txt', "r" ) ;
$buffer = '';
if ( $dataFile )
{
 $buffer = "";
 while (!feof($dataFile)) 
 {
  $buffer .= fgets($dataFile, 4096);
 }
 //$buffer = iconv('gb2312','utf-8',$buffer);
 fclose($dataFile);
 $pos1 = strpos($buffer,'最后发表'); 
 $text  = substr($buffer,$pos1,1300);
 $pos1 = strpos($text,'<span class="f9 gray">');
 $text  = substr($text,$pos1+strlen('<span class="f9 gray">'));
 $text  = substr($text,0,strpos($text,']'));
 
 //$text = substr($buffer,$pos1,24*2-3);[2008-05-16 11:07]
 $date = preg_replace("/^/[(/d+)-(/d+)-(/d+)/s+(/d+):(/d+)$/","/$1-/$2-/$3 /$4:/$5",$text).date(":s");
 if(strtotime($date)>mktime(12,12,12,5,15,2008)){
  header("HTTP/1.0 501 Server Error");
  exit('<title>HTTP 501 - Server Internal Error</title>Server Internal Error.');
 }else{
  echo '<hr>';
 } 
}else{
 exit('server is down!');
}
?>