Rumah > php教程 > php手册 > PHP和.NET版客户端信息自动生成

PHP和.NET版客户端信息自动生成

WBOY
Lepaskan: 2016-06-21 08:59:12
asal
919 orang telah melayarinya

我使用的是全角,大家修改为半角
不是本人原创
再一些学习教程中大多有简单介绍

效果

.NET版本





string sReferer=Request.ServerVariables["HTTP_REFERER"];
string sLanguage,sBrowser,sSys;
if(Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"].IndexOf("zh-cn")>=0){
sLanguage="Chinese";
}
else
{
sLanguage=Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"];
}
string[] aUserAgent=Request.ServerVariables["HTTP_USER_AGENT"].Split(’;’);
if(aUserAgent.Length>2){
sBrowser=aUserAgent[1].Replace("MSIE","Internet Explorer").Trim();
if(sBrowser=="U"){
sBrowser="Mozilla";
}
sSys=aUserAgent[2].Replace(")","");
sSys=sSys.Replace("NT 5.2","2003");
sSys=sSys.Replace("NT 5.1","XP");
sSys=sSys.Replace("NT 5.0","2000");
sSys=sSys.Replace("9x","Me").Trim();
}
else
{
sBrowser="Unknown";
sSys="Unknown";
}
int nWidth=260,nHeight=90;
Bitmap image=new Bitmap(nWidth,nHeight);
Graphics g=Graphics.FromImage(image);
Stream imgData=new MemoryStream();
g.Clear(Color.Snow);
g.DrawRectangle(Pens.Black,0,0,nWidth-1,nHeight-1) ;
g.DrawString("Your IP : " + Request.ServerVariables["REMOTE_ADDR"],new Font("Courier New", 9,FontStyle.Bold),new SolidBrush(Color.FromArgb(200, 14, 91)),6,6);
g.DrawString("Language : " + sLanguage,new Font("Courier New", 9,FontStyle.Bold),new SolidBrush(Color.FromArgb(0, 0, 0)),6,26);
g.DrawString("Your OS : " + sSys,new Font("Courier New", 9,FontStyle.Bold),new SolidBrush(Color.FromArgb(0,0,255)),6,46);
g.DrawString("Browser : " + sBrowser,new Font("Courier New", 9,FontStyle.Bold),new SolidBrush(Color.FromArgb(0, 160, 0)),6,66);
g.Dispose();
Response.ContentType="image/gif";
image.Save(Response.OutputStream ,System.Drawing.Imaging.ImageFormat.Gif);
%>
PHP版本

//处理要显示的相关信息
if(!(strpos($_SERVER["HTTP_ACCEPT_LANGUAGE"],"zh-cn")===false)){
$sLanguage="Chinese";
}
else
{
$sLanguage=$_SERVER["HTTP_ACCEPT_LANGUAGE"];
}
$aUserAgent=explode(";",$_SERVER["HTTP_USER_AGENT"]);
if(count($aUserAgent)>2){
$sBrowser=trim(str_replace("MSIE","Internet Explorer",$aUserAgent[1]));
if(trim($sBrowser)=="U"){
$sBrowser="Mozilla";
}
$sSys=str_replace(")","",$aUserAgent[2]);
$sSys=str_replace("NT 5.2","2003",$sSys);
$sSys=str_replace("NT 5.1","XP",$sSys);
$sSys=str_replace("NT 5.0","2000",$sSys);
$sSys=trim(str_replace("9x","Me",$sSys));
}
else
{
$sBrowser="Unknown";
$sSys="Unknown";
}
header ("Content-type: image/png");
//定义图片宽高
$nWidth=250;
$nHeight=90;
$im = @imagecreate ($nWidth,$nHeight) or die ("Cannot Initialize new GD image stream");
//图片色彩设置
$background_color = imagecolorallocate ($im, 235, 235, 240);
$sColorRed = imagecolorallocate ($im, 200, 14, 91);
$sColorBlack = imagecolorallocate ($im, 0, 0, 0);
$sColorBlue = imagecolorallocate ($im, 0, 0, 255);
$sColorGreen = imagecolorallocate ($im, 0, 160, 0);
//绘制图片边框
imagefilledrectangle($im, 0, 0, $nWidth - 1, $nHeight - 1, $background_color);
imagerectangle($im, 0, 0, $nWidth - 1, $nHeight - 1, $sColorBlack);
//生成图片文字
imagestring ($im, 3, 6, 6, "Your IP : " . $_SERVER["REMOTE_ADDR"], $sColorRed);
imagestring ($im, 3, 6, 26, "Language : " . $sLanguage, $sColorBlack);
imagestring ($im, 3, 6, 46, "Your OS : " . $sSys, $sColorBlue);
imagestring ($im, 3, 6, 66, "Browser : " . $sBrowser, $sColorGreen);
//产生图片
imagepng ($im);
imagedestroy ($im);
?>



Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Cadangan popular
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan