爬行的蜗牛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: golang Linux PHP
查看: 1053|回复: 0

帝国cms有访问才生成

[复制链接]

83

主题

31

回帖

780

积分

管理员

积分
780
发表于 2024-3-12 10:15:35 | 显示全部楼层 |阅读模式

本文实例讲述了帝国cms实现用户访问页面自动生成html的方法。分享给大家供大家参考。具体分析如下:

原因:对于服务器资源有限但是数据量非常庞大的网站来说,使用帝国cms在批量生成全部文件的时候速度比较慢,更改了一次模板,往往要更新很久.

思路:删除所有html->利用nginx匹配未生成的html->php生成html,如果nginx 检测html已经生成,则直接展示,不跳转到php.

实现代码如下:

  1. location /{  
  2. alias /home/web/xxx.com/;  
  3. if (!-e $request_filename) {  
  4. rewrite /(.*)/(.*).html$ /chtml.php?classid=1&id=$2&ssid=$2&check=checkcode;  
  5. }  
  6. }
复制代码

以上配置,用户访问不存在的html的时候会自动展示chtml.php里面的内容,网址不会跳转,相当于是在当前URL下.


3.php生成:

文件1:chtml.php代码如下:

  1. <?php  
  2. $check= stripslashes($_GET['check']);  
  3.   
  4. require('./class/connect.php');        //引入数据库配置文件和公共函数文件  
  5. require('./class/db_sql.php');        //引入数据库操作文件  
  6. require("./class/functions.php");  
  7. require("./class/t_functions.php");  
  8. require("./data/dbcache/class.php");  
  9. require("./data/dbcache/MemberLevel.php");  
  10. require('./class/chtmlfun.php');   
  11. $link=db_connect();                //连接MYSQL  
  12. $empire=new mysqlquery();        //声明数据库操作类  
  13.   
  14. if($check=="checkcode"){//checkcode 对应nginx配置的 checkcode  
  15. ReSingleInfo('userid','username');//你的帝国后台 id 和 用户名  
  16. }  
  17.    
  18. db_close();   //关闭MYSQL链接  
  19. $empire=null;  //注消操作类变量  
  20. ?>
复制代码

文件2修改:


e/class/chtmlfun.php

找到ReSingleInfo方法,在下面之前:

  1. $sql=$empire->query("select * from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where ".$add);
复制代码

新增:如下代码:

  1. /* 前台生成单个文件 2014-5-8 shanmao*/  
  2. $s_aid = (int)$_GET['ssid'];  
  3. if($s_aid>0){  
  4.     $add="id=$s_aid";  
  5.     $classid=58;//你的栏目id  
  6. }  
  7. /* 前台生成单个文件 */
复制代码

文件3修改:functions.php GetHtml 方法尾部新增一下代码,用于直接显示生成后的html:

  1. /* 直接展示html 2014-5-8    */  
  2. $s_aid = $_GET['ssid'];  
  3. $s_play = (int)$_GET['play'];  
  4. $s_check = $_GET['check'];  
  5. if($s_check=="checkcode"){  
  6.         if($s_aid && strstr($s_aid,"_play")){  
  7.             echo file_get_contents($file_p);  
  8.         }else{  
  9.             echo file_get_contents($file);  
  10.         }  
  11. }
  12. /* 直接展示html 2014-5-8    */
复制代码

希望本文所述对大家的帝国cms建站有所帮助。


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表