Jump to content

Create Cache File From Http_Host And Request_Uri


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.