theoforce 发表于 2015-8-27 07:38:16

ecshop模版文件中直接添加php代码的方法

  ecshop新版不能在模板文件.dwt和.lbi中直接添加php代码了,为什么呢?
因为直接在模板中加入php函数和代码,没有经过过滤,容易造成安全隐患。程序源码安全是非常重要的。
不过如果有朋友希望能在模板文件中直接加入.dwt和.lbi文件,怎么办呢?需要改动哪些文件呢?
其实,只需要改动一个文件,即includes/cls_template.php
打开此文件,找到函数 function fetch_str($source)
在此函数中找到
if(preg_match_all('~(<\?(?:\w+|=)?|\?>|language\s*=\s*[\"\']?php[\"\']?)~is', $source, $sp_match))
      {
            $sp_match = array_unique($sp_match);
            for ($curr_sp = 0, $for_max2 = count($sp_match); $curr_sp < $for_max2; $curr_sp++)
            {
                $source = str_replace($sp_match[$curr_sp],'%%%SMARTYSP'.$curr_sp.'%%%',$source);
            }
             for ($curr_sp = 0, $for_max2 = count($sp_match); $curr_sp < $for_max2; $curr_sp++)
            {
               $source= str_replace('%%%SMARTYSP'.$curr_sp.'%%%', '<?php echo \''.str_replace("'", "\'", $sp_match[$curr_sp]).'\'; ?>'." ", $source);
            }
         }
         
直接把这一段代码去掉或注释掉。
页: [1]
查看完整版本: ecshop模版文件中直接添加php代码的方法