Caching on shared server - security issue for local cache directory?
I am working with this script: http://www.cforcoding.com/2009/05/supercharging-javascript-part-4-caching.html
Basically the instructions recommend not to use caching if it will be used on a shared server.
Now I am using another script which dynamically generates a gif image from a font file and the text I provide and stores it in a local cache drive. Here is part of that code:
$hash = md5(basename($font_file) . $font_size . $font_color .
$background_color . $transparent_background . $text) ;
$cache_filename = $cache_folder . '/' . $hash . $extension ;
if($cache_images && ($file = @fopen($cache_filename,'rb'))) {
header('Content-type: ' . $mime_type) ;
while(!feof($file))
print(($buffer = fread($file,$send_buffer_size))) ;
fclose($file) ;
exit ;
}
So my 2 questions are:
1) For the code I pasted he开发者_运维百科re, is there any security issue?
2) And can I just use this piece of code which is used for caching with the website url I provided at the beginning ( http://www.cforcoding.com/2009/05/supercharging-javascript-part-4-caching.html ) Basically replace their caching method with this one to avoid security issues as mentioned. Or do you recommend some other method?
The author of the cforcoding.com guide was worried about security on a shared host because he was assuming CACHE_DIR was going to be a shared directory such as /tmp. But there is no reason you have to use /tmp for an arbitrary cache directory. You can just use a subdirectory from your user folder. So in your case as long as $cache_folder is not /tmp or another shared directory you will be okay (such as /home/user/mycache).
精彩评论