boionfire81 Posted June 2, 2016 Share Posted June 2, 2016 looking for a one liner (ie include ****.php or $background) for my header that will give each page it's own background. So if the member is on shops.php background image = shops.png, jail.php = jail.png, attack.php = attack.png, etc Quote Link to comment Share on other sites More sharing options...
SRB Posted June 3, 2016 Share Posted June 3, 2016 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 Quote Link to comment Share on other sites More sharing options...
Dayo Posted June 4, 2016 Share Posted June 4, 2016 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>"; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.