帝国cms php调用文本里面的随机行

时间:2023年09月17日

/

来源:网络

/

编辑:佚名

帝国cms php调用文本里面的随机行代码
function rand_txt($filename = "hot", $type = 1){
    if(!file_exists(ECMS_PATH."d/{$filename}.txt")){
        return "请检查网站根目录下/d/{$filename}.txt文件是否存在。";
        exit;
    }
    $file=@file_get_contents(ECMS_PATH."d/{$filename}.txt");
    $ci = explode("\n",$file);
    if(empty($ci)){
        return "请检查网站根目录下/d/{$filename}.txt文件是否存在内容。";        
    }
    if($type == 2){
        $filecache = ECMS_PATH."d/json/".md5('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']).".json";
        if(!file_exists($filecache)){ 
          @mkdir(ECMS_PATH."d/json",0777); 
          @chmod(ECMS_PATH."d/json",0777); 
          $row = mt_rand(0,count($ci)-1);
          file_put_contents($filecache,$row);
          return $ci[$row];
        }else{
           $row = file_get_contents($filecache);
           return $ci[$row];
        }
    }
    return $ci[mt_rand(0,count($ci)-1)];
}
猜你需要

豫ICP备2021026617号-1  豫公网安备:41172602000185   Copyright © 2021-2028 www.78moban.com/ All Rights Reserved

本站作品均来自互联网,转载目的在于传递更多信息,并不代表本站赞同其观点和对其真实性负责。如有侵犯您的版权,请联系 1565229909#qq.com(把#改成@),我们将立即处理。