Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 [2]

Author Topic: Forum Code Thread  (Read 4285 times)

Starver

  • Bay Watcher
    • View Profile
Re: Forum Code Thread
« Reply #15 on: November 07, 2015, 04:44:17 am »

If you have enough control over the web server (needs a non-basic hosting package), you should be able to override the MIME-type handler for a specific file, e.g. "changeable.png" so that the contents are equivalent to "changeable.php" (or, my preference, ".pl") which contains the basic code for deciding between possible source images (to directly read the binary of, or otherwise derive/render-on-the-fly if you don't mind the possible processing overheads) and returning them as an HTTP response to the "changeable" request, not forgetting to set the correct image-style "Content-Type" in the process.

You might be able to just do <img src="changeable.php" />, skipping the need to get into the httpd.conf (or whatever), but I'm not sure if that'll work properly in all cases, and you probably still need to $response->content_type("image/png") (or .php version of that, as well as perhaps being a different image/*, according to what you're sending.

The very simplest way of doing this in a standard web-setting is doing something like an <IFRAME src=changablepage.php /> where the return is not the image, but the frame-page that contains whatever variant on <img src="this.png" />, <img src="that.gig" /> or <img src="theother.jpg" /> according to the decision, to reference the static image versions.  But I'm not sure if/how that would work within the BBCode environment of a forum post or .signature...


(The very first time I did anything like this, in the earliest days of the Web was on a university server where I just invoked a cron command to dynamically switch in (e.g. "cp xmaseve.html home.html") different versions of my web-page, over the Christmas holidays, whilst I was away from campus.  Not that I think anyone noticed that it changed from the pre-Christmas Eve version to the Christmas Eve version to the Christmas Day one, and so on until Hogmanay, in time for my return.  There weren't exactly that many web-users in '92 or maybe it was '93...  I don't think I even expected it to be anything more than a fad, compared with the other more long-standing internet services of the time... ;) ...anyway, I doubt this mechanism is open to the OP, I'm just mentioning it for completeness.)
Logged
Pages: 1 [2]