Computerglitch

An ongoing adventure

IP Address to Image

This is a small php script I wrote to display remote ip addresses on a web page and convert the resulting ip address to a image to blend in better with the page.


Here is the code, name this ip.php or similar:[download ip.php]

<?PHP
function z_imgcode($num) {
$img_code = "<img src=\"num_jpgs/$num.jpg\" border=\"0\">";
return $img_code;
}

$splitip = chunk_split($_SERVER['REMOTE_ADDR'], 1, ',');
$iparr = explode(",", $splitip);
for($i=0;$i<sizeof($iparr);$i++) {
if($iparr[$i] != "") {
if($iparr[$i] != ".") {
$ipstring .= z_imgcode($iparr[$i]);
} else {
$ipstring .= "<img src=\"num_jpgs/dot.jpg\" border=\"0\">";
}
}
}
echo $ipstring;
echo "<br>";
?>

You will need to create a folder in the same directory as the script with the name num_jpgs. In this folder create seperate number jpgs 0 - 9 and dot.jpg (example 0.jpg, 1.jpg, 2.jpg, etc etc.)


Example output can be seen here


Comments