PHP - How to display IP address of a visitor?

December 2016






Simple method
<? 

echo $_SERVER["REMOTE_ADDR"]; 

?>

Displaying IP in a graphic mode

Show IP Display visitor's IP Address in a graphic with this simple php code.
Consider that:
Your IP Address
40.206.137.115
Create a new page, copy the text below and save it as image.php (or whatever you wish)
<?php
$img_number = imagecreate(275,25);
$backcolor = imagecolorallocate($img_number,102,102,153);
$textcolor = imagecolorallocate($img_number,255,255,255);

imagefill($img_number,0,0,$backcolor);
$number = " Your IP is $_SERVER[REMOTE_ADDR]";

Imagestring($img_number,10,5,5,$number,$textcolor);

header("Content-type: image/jpeg");
imagejpeg($img_number);
?>



All you'll need to display on other pages is the code below.

<img src="http://mysite.com/image.php" border="1">

Related :

This document entitled « PHP - How to display IP address of a visitor? » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.