Last updated on January 17, 2018
This Post is About Displaying IP Address in Image format, in my previous post I wrote about getting real IP Address using PHP(How to get Real IP from Visitor?).
Here is the code, just create image.php
, copy paste the code
// function to get ip address function get_client_ip() { if ($_SERVER['HTTP_CLIENT_IP']) $ipaddress = $_SERVER['HTTP_CLIENT_IP']; else if($_SERVER['HTTP_X_FORWARDED_FOR']) $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR']; else if($_SERVER['HTTP_X_FORWARDED']) $ipaddress = $_SERVER['HTTP_X_FORWARDED']; else if($_SERVER['HTTP_FORWARDED_FOR']) $ipaddress = $_SERVER['HTTP_FORWARDED_FOR']; else if($_SERVER['HTTP_FORWARDED']) $ipaddress = $_SERVER['HTTP_FORWARDED']; else if($_SERVER['REMOTE_ADDR']) $ipaddress = $_SERVER['REMOTE_ADDR']; else $ipaddress = 'UNKNOWN'; return $ipaddress; } //imagecreatetruecolor - Create a new true color image $img = imagecreatetruecolor(275,25); //imagecolorallowcate - Allocate a color for an image $backcolor = imagecolorallocate($img,102,102,153); $textcolor = imagecolorallocate($img,255,255,255); // imagefill - Flood fill imagefill($img,0,0,$backcolor); $number = " Your IP is ".get_client_ip(); //imagestring — Draw a string horizontally imagestring($img,10,5,5,$number,$textcolor); header("Content-type: image/jpeg"); //imagejpeg — Output image to browser or file imagejpeg($img);