<div style='background-color: none transparent;'></div>
Home » » Databases sample source codes

Databases sample source codes

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

/*this function converts $ipaddr into a color string*/
function IP2Color($ipaddr) {

$pieces=explode(".",$ipaddr);
$color="";

for($i=0;$i<3;$i++) {
if(($pieces[$i]>=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 "
color='".IP2NotColor($IP)."'>$IP
\n";
?>
Share this article :
 
Copyright © 2011. B.Sc B.Tech MCA Ploytechnic Mini,Main Projects | Free Main Projcets Download | MCA |B.tech . All Rights Reserved
Company Info | Contact Us | Privacy policy | Term of use | Widget | Advertise with Us | Site map
Template Modify by Creating Website. Inpire by Darkmatter Rockettheme Proudly powered by Blogger