Very strange: Empty CSS background image executes PHP script

Imagine you put the following simple PHP script at some webspace (let’s say at http://www.domain.com/path/file.php) and call it from your web browser…

<html>
  <body style="background: url();">
    <?php error_log('WHOW!'); ?>
  </body>
</html>

What would you say if I claimed that the text “WHOW!” would appear twice in your PHP error log? And moreover I purport that this happens only when you use Firefox or Chrome to call the script – IE is not affected by this funny artifact.

This obviously has something to do with the style attribute of the body-tag. According to some quick tests that I did, the reason is the way the browsers resolve the empty image resource of the background style. In fact they internally use a default background image URL which is different for each browser:

FF 3.6:      http://www.domain.com/path/file.php
Chrome 7.0:  http://www.domain.com/path/file.php
IE 8:        http://www.domain.com

And these URLs really get polled to retrieve an image! As the URLs of Chrome and FF are pointing back to the script itself, it gets executed twice with each call of the page!

If you use this script as a target action for an HTML form, the first call receives the form data, the second call (the image request) receives nothing at all.

In Chrome (not in FF though) this also happens with <img src=”">.

Dieser Beitrag wurde unter Bug, HTML, PHP abgelegt und mit , , verschlagwortet. Setze ein Lesezeichen auf den Permalink.

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

Du kannst folgende HTML-Tags benutzen: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>