将PHP页面显示为图像
嗨,我有一些PHP脚本,显示基于访客ip的国旗 flags.php将PHP页面显示为图像,php,ip,country,Php,Ip,Country,嗨,我有一些PHP脚本,显示基于访客ip的国旗 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
<?
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>";
}
<img src="http://ip.dxing.si/flags/flags.php">
您不应该将php文件作为src属性包含在img标记中,只需包含php文件(它将回显img标记)
index.php
include 'flags.php'; //this will echo the entire img-tag
或者,让flags.php读取并回显整个标志图像。或者让它回显url(但是您可以将其作为一个函数运行,不需要将其作为一个单独的文件保存)这是因为flags.php文件实际输出的内容,并且路径适合包含的文件,而不是index.php
它正在创建一个完整的img
标记,而在索引文件中,您仅将其用作src
属性
将flags.php更改为
$file\u to\u check=“flags/flags/$two\u letter\u country\u code.gif”;
如果(文件存在($file-to-check)){
打印$file\u to\u check“;
}否则{
打印“flags/flags/noflag.gif”;
}Flags.php返回img标记,而不是src
在index.php中,不能添加
,而只能添加http://ip.dxing.si/flags/flags.php
只需将您的flags.php
包含在index.php
中,您就可以了。它不起作用。当我单独访问脚本时,它会返回:flags/SI.gif,但当我访问索引页时,它仍然是一张破碎的图像(我想知道他们是怎么做到的:)啊,那就是路径错了。我已经编辑了我的答案来纠正这一点,但是如果你想让它在两个文件上都起作用,你需要对图像文件使用绝对路径。