//************************************** // Name: IP2Color // Description:A couple of functions that convert an IP address into its color code and not-color-code. Useful when viewing an apache log with a mysql result grouped by IP // By: FabieADI // // Inputs:IP address // // Returns:formatted HTML with a colored IP address on a contrasted background // // Assumes:A color is defined by the three components Red Green & Blue, to define the color of IP address w.x.y.z, I take w for red, x for green and y for blue, the 'not-color' is the base color translated by 128 // // Side Effects:Some IPs produce a not so contrasted background, because the coloring function could be improved // //This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=319&lngWId=8//for details.//************************************** =0) && ($pieces[$i]<=255)) { $color.=dechex($pieces[$i]); } } $color=substr($color."000000",0,6); return("#".strtoupper($color)); } /***********************************/ /*this function converts $ipaddr to anti color string*/ function IP2NotColor($ipaddr) { $pieces=explode(".",$ipaddr); $color=""; for($i=0;$i<3;$i++) { if(($pieces[$i]>=0) && ($pieces[$i]<=255)) { $color.=dechex((128+$pieces[$i]) % 255); } } $color=substr($color."000000",0,6); return("#".strtoupper($color)); } Example: $IP=getenv("REMOTE_ADDR"); print "\n"; print "\n"; print "
$IP
\n"; ?>