将PHP页面显示为图像
发布时间:2020-12-13 15:57:46 所属栏目:PHP教程 来源:网络整理
导读:嗨,我有一些 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_cod
嗨,我有一些
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($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>"; } 然后在我的索引页面中我做了 的index.php <img src="http://ip.dxing.si/flags/flags.php"> 当我单独运行脚本时,它显示标志就好了,但是当我想在另一个页面上显示它时它不起作用. Here是脚本,here是索引页面,图像已损坏. 解决方法
您不应该将您的php文件包含在img标记中的src属性中,只需包含php文件(它将回显img标记)
的index.php include 'flags.php'; //this will echo the entire img-tag 或者,使您的flags.php读取并回显整个标志图像.或者让它回显url(但是你可以将它作为一个函数运行而不需要将它作为一个单独的文件保存) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |