我要投稿
  • 您当前的位置:57365.com -> 技术教程 -> 网站建设教程 -> 源码精华 -> 教程内容
  • [ 收藏本页教程 ]
  • php版客户端信息自动生成源代码源码精华教程

    教程作者:佚名    教程来源:不详   教程栏目:源码精华    收藏本页
    效果

    Click to Open in New Window

    调用:

    [img]http://demo.cms8.com/ip.php[/img]

    代码:

    <%@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
    //处理要显示的相关信息
    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);
    ?>

    (出处:

    我要投稿   -   广告合作   -   关于本站   -   友情连接   -   网站地图   -   联系我们   -   版权声明   -   设为首页   -   加入收藏   -   网站留言
    Copyright © 2009 - 20012 www.www.hxswjs.com All Rights Reserved.57365.com 版权所有