Jump to content
MakeWebGames

unique page backgrounds


Recommended Posts

Assuming you're using PHP with the files ending in .php, you could simply do something like this;

 

<table style="background-image: url(images/backgrounds/<?=substr(str_replace('/', '', $_SERVER['PHP_SELF']), 0, -4); ?>.png);">

 

Simply sets the background-image to be the url with the following conditions;

Images are in the directory - images/backgrounds

Ends in PHP

Images are PNG.

-- Edit

Codepad parses via t.php, which results in t.png

http://codepad.org/kwyfk85q

Link to comment
Share on other sites

This is similar to the one above but checks if the background exists, if not will load the default background image, you may have to change the CSS class to match your HTML/CSS

<?php
   $file = "/path/to/images" . pathinfo(__FILE__, PATHINFO_FILENAME) . ".png";
   if (!file_exists($file)) $file = "/path/to/default/background.png";
   echo "<style> .header { background-image: url('$file'); background-size: cover; } </style>";
?>
Link to comment
Share on other sites

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.   Paste as plain text instead

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