How to change background image with the help of url parameter in php?

40
April 16, 2019, at 12:00 PM

I'm trying to change background image of a simple php page with help url parameter. I'm very newbie and don't know much coding.

<img width="250" src="https://i.imgur.com/<?php echo $_GET['img']; ?>.png">

When i use the above code in url i will get desire image from imgur.com by just entering the image link for example:

http://example.com/?img=frotzyG (full image url: https://i.imgur.com/frotzyG.jpg)

but it just show in a div e.g.

<div class="abc">
<img width="250" src="https://i.imgur.com/<?php echo $_GET['img']; ?>.png">
</div>

Now i want the same thing to happen for background image. I have a simple php page and its background image source is located in a css (e.g stylesheet.css)

Here's CSS file code:

body {
  background: url(images/bg.jpg) no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

How to change background image with the help of url parameter (or whatever you call it.)

P.S. Sorry for my bad English, hope you understand my point.

Answer 1

You might move css related to background image into HTML using style tag.

<style>
  body {
    background-image: url(https://i.imgur.com/<?php echo $_GET['img']; ?>.jpg);
  }
</style>
READ ALSO
how to fix with this error A PHP Error was encountered, I have got a similar reference but still failed. I need a solution? [on hold]

how to fix with this error A PHP Error was encountered, I have got a similar reference but still failed. I need a solution? [on hold]

How to fix this error, i create apps for hospital with codeigniter, I have downgraded xampp from version 71 to 5

49
How to read soap response header

How to read soap response header

Getting response from one of the soap function php, after that sending this response as a parameter to another soap request, that time I need to extract the set-cookie from the previous response header here below my response headerI need to read set-cookie...

30
PHP debug recursion

PHP debug recursion

I have a problem when I want to add debugging for recursion to send me the backtrace to show in which file an error occured (I'm not able to debug because the code is on another server)

30
What is the PDO equivalent of function mysql_real_escape_string?

What is the PDO equivalent of function mysql_real_escape_string?

I am modifying my code from using mysql_* to PDOIn my code I had mysql_real_escape_string()

53