Jump to content

Create Cache File From Http_Host And Request_Uri


stegers

Recommended Posts

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

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 ("/").

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.