PHP Script to Show Visitor’s IP Address

Dzhuneyt Ahmed - Author of this post
Dzhuneyt Ahmed

Posted · 1 min read

PHP Script to Show Visitor’s IP Address

Sometimes you want to get the visitor’s IP address (e.g to show it to him or for logging purposes). This simple snippet does the job:

$ip = $_SERVER['REMOTE_ADDR'];

Also, if you have REGISTER_GLOBALS turned on on your server, you can use the shorter version:

$ip = @$REMOTE_ADDR;

Then you can easily use the variable called $ip for your needs.
[ad name=”In Post”]

Dzhuneyt Ahmed

Dzhuneyt

Helping teams build reliable cloud infrastructure — without the bloated bill.

Social

My Other Blogs

© 2026 Dzhuneyt Ahmed. All rights reserved.