To add one feature to over 100 .htm files (to display a eu cookie law popup) could this proposed system work:
htaccess:
redirect all incoming .htm requests to cookie.php
inside cookie.php:
$_SERVER['REQUEST_URI']
perform document search to get element in head, function{
include cookie display files
}
document search for element in footer, function{
Add <a href="#">Cookie Policy</a>
}
Send data to client browser
I have some things I am uncertain of.
- would each URL not read: example.com/cookie.php
- I am unsure how to actually spit data out using request_uri
Is this possible?
It sounds like you’re lumbered with a static website that lacks any hooks into a dynamic environment.
My approach here would be to do a global find-and-replace to insert a single hook into each file, such that you can do whatever you want to any file via that central hook.
I’d try to insert this into the pages’ main content area. Granted this assumes each page has a similar structure – if not, you’ll need different find-and-replace operations to insert the hook into different types of page. Let’s assume each page had a main content area, a
divwith IDmain.In your text editor you’d do a REGEX replace along the lines of:
I’m assuming a couple of things about your text editor’s REGEX implementation there, but essentially I’m inserting the PHP hook directly after the
div‘s opening tag.Then, in hook.php, you can do what you want. So output cookie information, or whatever.
An easier approach would be to harness any common JS hook that each page shares. So if every page loaded common.js or whatever, you could do a similar thing as described as above – only the content would be DOM-scripted into the page rather than into the source code, which is less ideal if the content is SEO sensitive.