stegers Posted December 23, 2012 Share Posted December 23, 2012 Hello ; I am writing a piece of code to create cache files from a certain site and all its pages. Because we display different data from the database using server alias configuration we need to create cache files with http_host and request_uri combined. Otherwise displayed cached will be displayed on wrong sites. I already created a piece of code, but does not work properly ... Here is the part wit the problem: $filename = "cache/".basename(rtrim($_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"], '/')).".cache"; I would like the combine HTTP_HOST and REQUEST_URI into 1 file, now it create 2 files. 1 for index and 1 for every other page visited. Thanks ; Pascal Quote Link to comment https://forums.phpfreaks.com/topic/272312-create-cache-file-from-http_host-and-request_uri/ Share on other sites More sharing options...
stegers Posted December 23, 2012 Author Share Posted December 23, 2012 Already found it : $filename = "cache/".basename(rtrim($_SERVER["HTTP_HOST"], '/')).basename(rtrim($_SERVER["REQUEST_URI"], '/')).".cache"; thanks anyway Quote Link to comment https://forums.phpfreaks.com/topic/272312-create-cache-file-from-http_host-and-request_uri/#findComment-1401013 Share on other sites More sharing options...
requinix Posted December 23, 2012 Share Posted December 23, 2012 That may be correct for you but in the general case, and actually I would suspect your case even, that won't work. It'll use the same cache for example.com/file.php as it would example.com/path/to/file.php. The first basename() and rtrim() is totally unnecessary while the second basename() is the problem. You're also not doing any kind of checking on the names provided, like with unsafe characters (there are many which aren't valid for Windows file names) or query strings ("?") or subdirectories ("/"). Quote Link to comment https://forums.phpfreaks.com/topic/272312-create-cache-file-from-http_host-and-request_uri/#findComment-1401053 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.