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

664

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.

180

Answer

Solution:

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>

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

Source

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.