2

I have the following code that determines if an image is an SVG or not so that it displays the source if it is (the SVG can then be coloured using CSS):

if (strpos('url_to_an_image', '.svg') !== false) {
    echo file_get_contents('url_to_an_image'); 
} else {
    echo '<img src="url_to_an_image" />';
}

This worked fine, until I added an IP restriction in htaccess when I get the following error:

file_get_contents(http://example.com/images/icons/icon-email.svg): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden

I have tried the solutions that suggest spoofing a real browser request; they don't work.

Is there another solution for this, or another approach I could use to display SVGs?

freginold
  • 3,946
  • 3
  • 13
  • 28
greebstreebling
  • 316
  • 1
  • 2
  • 13

2 Answers2

1

i had the same issue and finally found out what happened. My VPS provider put in a "deny from all" in the .htaccess after putting in a huge list of "allow from" IP addresses.

They did this because of a bonet attack on the site.

jDeep
  • 11
  • 2
0

You're getting the 403 error because php doesn't seem to have the permission to open this file. What's your exact code to block the IPs? Do not use an URL when it's on your own server, just use an absolute path.

dmuensterer
  • 1,875
  • 11
  • 26