ecshop新版不能在模板文件.dwt和.lbi中直接添加php代码了,为什么呢?
因为直接在模板中加入php函数和代码,没有经过过滤,容易造成安全隐患。程序源码安全是非常重要的。
不过如果有朋友希望能在模板文件中直接加入php代码,怎么办呢?
其实,只需要改动一个文件,即includes/cls_template.php
打开此文件,找到函数 function fetch_str($source)
在此函数中找到,大概在288行

        if(preg_match_all('~(<\?(?:\w+|=)?|\?>|language\s*=\s*[\"\']?php[\"\']?)~is', $source, $sp_match))
        {
            $sp_match[1] = array_unique($sp_match[1]);
            for ($curr_sp = 0, $for_max2 = count($sp_match[1]); $curr_sp < $for_max2; $curr_sp++)
            {
                $source = str_replace($sp_match[1][$curr_sp],'%%%SMARTYSP'.$curr_sp.'%%%',$source);
            }
             for ($curr_sp = 0, $for_max2 = count($sp_match[1]); $curr_sp < $for_max2; $curr_sp++)
            {
                 $source= str_replace('%%%SMARTYSP'.$curr_sp.'%%%', '<?php echo \''.str_replace("'", "\'", $sp_match[1][$curr_sp]).'\'; ?>'."\n", $source);
            }
         }

        
直接把这一段代码删除或注释。
登录一下后台更新缓存,你再在模板文件中插入php代码试试。

 

相关文章:

  • 2021-08-28
  • 2022-12-23
  • 2021-07-29
  • 2021-11-21
  • 2022-12-23
  • 2022-01-06
  • 2021-05-29
猜你喜欢
  • 2022-02-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案