Show PHP pages as image

Hi I have a PHP script that shows a country flag based on ip visitors

flags.php

<?
require 'ip.php';
$ip=$_SERVER['REMOTE_ADDR'];
$two_letter_country_code=ip_info("$ip", "Country Code");

//header('Content-type: image/gif');
$file_to_check="flags/$two_letter_country_code.gif";
if (file_exists($file_to_check)){
    print "<img src=$file_to_check width=30 height=15><br>";
}
else{
    print "<img src=flags/noflag.gif width=30 height=15><br>";
}

Then on my index page I did

index.php

<img src="http://ip.dxing.si/flags/flags.php">

When I run only the script, it shows the flag just fine, but when I want to show it on another page, it does not work.

Here is the script and here are the pages with the broken image.

+4
source share
3 answers

You should not include your php file as an src attribute in the img tag, just include the php file (and it will be an img echo tag)

index.php

include 'flags.php'; //this will echo the entire img-tag

flash.php -. -url ( )

+1

- , flags.php, , index.php

img, src.

.php   $ File_to_check = "//$two_letter_country_code.gif";   if (file_exists ($ file_to_check)) {               print $file_to_check ";               } {               print" flags/flags/noflag.gif";               }

0

Flags.php returns an img tag, not src.

In index.php you should not add <img src="http://ip.dxing.si/flags/flags.php">, but justhttp://ip.dxing.si/flags/flags.php

0
source

All Articles