Automatic generation of PHP and. NET version of client information

Source: Internet
Author: User
Tags php and servervariables trim

I'm using a full angle, and we're changing it to half a corner.
Not my original
Some of the other learning tutorials are briefly introduced

Effect

. NET version

<% @Page language= "C #" debug= "true"%>
<% @Import namespace= "System"%>
<% @Import namespace= "System.Drawing"%>
<% @Import namespace= "System.IO"%>
<%
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 Version

<?php
Working with related information to display
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", "Watts", $sSys);
$sSys =trim (Str_replace ("9x", "Me", $sSys));
}
Else
{
$sBrowser = "Unknown";
$sSys = "Unknown";
}
Header ("Content-type:image/png");
Define Picture Width height
$nWidth = 250;
$nHeight = 90;
$im = @imagecreate ($nWidth, $nHeight) or Die ("Cannot Initialize new GD image Stream");
Picture color settings
$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);
Draw a picture border
Imagefilledrectangle ($im, 0, 0, $nWidth-1, $nHeight-1, $background _color);
Imagerectangle ($im, 0, 0, $nWidth-1, $nHeight-1, $sColorBlack);
Generate Picture Text
Imagestring ($im, 3, 6, 6, "Your IP:". $_server["REMOTE_ADDR"], $sColorRed);
Imagestring ($im, 3, 6, num, "Language:". $sLanguage, $sColorBlack);
Imagestring ($im, 3, 6, +, "Your OS:". $sSys, $sColorBlue);
Imagestring ($im, 3, 6,, "Browser:". $sBrowser, $sColorGreen);
Produce picture
Imagepng ($im);
Imagedestroy ($im);
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.