/    Sign up×
Community /Pin to ProfileBookmark

Loading a background image from array

Hi everyone,

I have coded in html/php/css, but have not done anything too elaborate. I was looking at a site that had a different image every time on reload. When looking at the source code for the site, I found the following code that was placing the background.

<style type=”text/css”>
body {
background-image: url(assets/bg002.jpg);
}
</style>

On every reload the “bg002.jpg” portion of the code would change. Can anyone explain a method or script that could be causing this? There is no other code on the page that would refer to an array that the background images are being caller from.

Many thanks in advance!!

to post a comment
CSS

2 Comments(s)

Copy linkTweet thisAlerts:
@Dave_LaneNov 06.2010 — If there's no hint of anything in the page source, they're using a scripting language like PHP to randomly select the image filename before the page is rendered in your web browser.

It's the same as doing the following:

[CODE]
<?php
$myVar = "Hello";
echo $myVar;
?>
[/CODE]


When this script is executed and rendered in the browser, you would see only the text "Hello".

Similarly, the "bg002.jpg" portion of the page source you're looking at is being printed using some random value. You just can't see the code used to choose the image filename because that processing is done on the server side (before your browser receives a response from the web server); you just see the output of some echo statement.
Copy linkTweet thisAlerts:
@WebAppleauthorNov 06.2010 — Hi Dave,

That helped clear it up! I thought this might be one way to achieve this and just wanted to get an affirmation.

Thanks for all your help. This should help get me started!
×

Success!

Help @WebApple spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...