Home > php教程 > php手册 > 修改ThinkPHP3.2的F方法

修改ThinkPHP3.2的F方法

WBOY
Release: 2016-06-07 11:40:42
Original
2459 people have browsed it

修改ThinkPHP3.2的F方法
ThinkPHP3.2的F采用的是序列化方式保存数据,由于F方法保存的文件名是已知的
可能造成一些数据泄露,所以在此修改F方法

直接替换TP的F方法即可function F($name, $value='', $path=DATA_PATH) {<br>     static $_cache  = array();<br>     $filename       = $path . $name . '.php';<br>     if ('' !== $value) {<br>         if (is_null($value)) {<br>             // 删除缓存<br>             return false !== strpos($name,'*')?array_map("unlink", glob($filename)):unlink($filename);<br>         } else {<br>             // 缓存数据<br>             $dir            =   dirname($filename);<br>             // 目录不存在则创建<br>             if (!is_dir($dir))<br>                 mkdir($dir,0755,true);<br>             $_cache[$name]  =   $value;<br>             return file_put_contents($filename, strip_whitespace("<?php \treturn " . var_export($value, true) . ";?>"));<br>         }<br>     }<br>     if (isset($_cache[$name]))<br>         return $_cache[$name];<br>     // 获取缓存数据<br>     if (is_file($filename)) {<br>         $value          =   include $filename;<br>         $_cache[$name]  =   $value;<br>     } else {<br>         $value          =   false;<br>     }<br>     return $value;<br> }QQ交流群:17540504

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template