PHP logs visitors ' information and generates pictures

Source: Internet
Author: User
Tags ereg log return linux

PHP Records visitors ' information and generates pictures, as shown below.

The code is as follows, this article only wrote some elementary things, the need of friends can be modified according to their own situation.

<?php//function: Visit information generate picture function Getbrowse () {//log visitor's browser information global $_server;
	$Agent =$_server["Http_user_agent"];
	$browseinfo = "";
	if (Ereg ("Mozilla", $Agent) &&!ereg ("MSIE", $Agent)) {$browseinfo = "Netscape Navigator";
	} if (Ereg ("opera", $Agent)) {$browseinfo = "opera";
	} if (Ereg ("Mozilla", $Agent) &&ereg ("MSIE", $Agent)) {$browseinfo = "Internet Explorer";
	} if (Ereg ("Chrome", $Agent)) {$browseinfo = "chrome";
	} if (Ereg ("Firefox", $Agent)) {$browseinfo = "Firefox";
return $browseinfo;
	function GetIP () {//log visitor's IP information global $_server;
	if (getenv ("Http_client_ip")) {$ip =getenv ("http_client_ip");
	}else if (getenv ("Http_x_forwarded_for")) {$ip =getenv ("http_x_forwarded_for");
	}else if (getenv ("REMOTE_ADDR")) {$ip =getenv ("remote_addr");
	}else{$ip =$_server["REMOTE_ADDR"];
return $IP;
	The function Getos () {//records the visitor's system information global $_server;
	$agent =$_server["Http_user_agent"];
	$os =false;
	if (Eregi ("Win", $agent) &&strpos ($agent, "a")) {$os = "Windows 95"; }eLSE if (EREGI ("Win 9x", $agent) &&strpos ($agent, "4.90")) {$os = "Windows ME";
	}else if ("Win", $agent) &&ereg ("Eregi", $agent)) {$os = "Windows 98";
	}else if (eregi ("Win", $agent) &&eregi ("NT 5.1", $agent)) {$os = "Windows XP";
	}else if (eregi ("Win", $agent) &&eregi ("NT 5.2", $agent)) {$os = "Windows 2003";
	}else if (eregi ("Win", $agent) &&eregi ("NT 5", $agent)) {$os = "Windows 2000";
	}else if (eregi ("Win", $agent) &&eregi ("NT", $agent)) {$os = "Windows nt";
	}else if (eregi ("Win", $agent) &&ereg ("A", $agent)) {$os = "Windows 32";
	}else if (eregi ("Linux", $agent)) {$os = "Linux";
	}else if (eregi ("Unix", $agent)) {$os = "Unix";
	}else if (Eregi ("Sun", $agent) &&eregi ("OS", $agent)) {$os = "SunOS";
	}else if (eregi ("IBM", $agent) &&eregi ("OS", $agent)) {$os = "IBM OS/2";
	}else if (eregi ("Mac", $agent) &&eregi ("PC", $agent)) {$os = "Macintosh";
	}else if (eregi ("PowerPC", $agent)) {$os = "PowerPC"; }else if (eregi ("Aix", $agent)) {$os = "Aix";
	}else if (eregi ("HPUX", $agent)) {$os = "HPUX";
	}else if (eregi ("NetBSD", $agent)) {$os = "NetBSD";
	}else if (eregi ("BSD", $agent)) {$os = "BSD";
	}else if (ereg ("OSF1", $agent)) {$os = "OSF1";
	}else if (ereg ("IRIX", $agent)) {$os = "IRIX";
	}else if (eregi ("FreeBSD", $agent)) {$os = "FreeBSD";
	}else if (eregi ("Teleport", $agent)) {$os = "teleport";
	}else if (eregi ("FlashGet", $agent)) {$os = "flashget";
	}else if (eregi ("Webzip", $agent)) {$os = "webzip";
	}else if (eregi ("Offline", $agent)) {$os = "offline";
	}else{$os = "Unknown";
return $os;
} $ob =getbrowse ();
$os = Getos ();
$ip =getip ();
$str = "IP:". $ip;
$str 2= "OS:". $os;
$str 3= $ob;
$str 4= "from:www.Alixixi.com";
$width the width of the =250;//verification code picture $height the height of the =110;//Verification Code picture @header ("content-type:image/png");
$im =imagecreate ($width, $height);
Background color $back =imagecolorallocate ($im, 0xff,0xff,0xff);
Fuzzy point color $pix =imagecolorallocate ($im, 187,230,247);
Font Color $font =imagecolorallocate ($im, 41,163,238);
A point Mt_srand () that paints a blur action; For ($i =0 $i <1000; $i + +) {Imagesetpixel ($Im,mt_rand (0, $width), Mt_rand (0, $height), $pix);
Imagestring ($im, 5,7,5, $str, $font);
Imagestring ($im, 5,7,30, $str 2, $font);
Imagestring ($im, 5,7,55, $str 3, $font);
Imagestring ($im, 5,7,80, $str 4, $font);
Imagerectangle ($im, 0,0, $width-1, $height-1, $font);
Imagepng ($im); Imagedestroy ($im);

Articles that you may be interested in

    • PHP to judge the function of visiting spider information
    • PHP Records search engine antecedents and search input keywords
    • How to use jquery to control the display of a user-uploaded picture that is too wide
    • How PHP clears HTML formatting and removes spaces from text and then intercepts text
    • A program in which PHP gets all the files in the directory and saves the results to an array
    • PHP Generate dynamic Captcha picture (GIF)
    • PHP Gets the list of all the pictures in the content and outputs the method
    • A function of PHP to read directories and tables to display files in a directory


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.