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


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="<?php echo $_GET['img']; ?>.png">

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

but it just show in a div e.g.

<div class="abc">
<img width="250" src="<?php echo $_GET['img']; ?>.png">

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.




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

  body {
    background-image: url(<?php echo $_GET['img']; ?>.jpg);

People are also looking for solutions to the problem: php - Command cim was not found. Drush was unable to query the database


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.