How to grab IP address with PHP
Wednesday, March 28, 2012
Posted by Priya Yadav
Today I’ll be showing you how to grab somebodies IP address when they visit a page.
The variable to use is $_SERVER['REMOTE_ADDR'] - It’s that simple. You can use it
for just about anything, here are a few examples.
Printing the Users IP Address:
<?php
print ($_SERVER['REMOTE_ADDR'], "I'm Watching You!");
?>
Printing it to a File:
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$handle = fopen('ipaddresses.txt'', 'a+);
fwrite($handle, $ip); fwrite($handle, "\n");
fclose($handle);
?>
All you have to do, is to make a text file and insert any of these codes or one of your
own and save it as anythingyouwant.php
Then upload it to your website and it'll do the trick :P
The Possibilities for what you can use this to are endless.
Good luck :D
The variable to use is $_SERVER['REMOTE_ADDR'] - It’s that simple. You can use it
for just about anything, here are a few examples.
Printing the Users IP Address:
<?php
print ($_SERVER['REMOTE_ADDR'], "I'm Watching You!");
?>
Printing it to a File:
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$handle = fopen('ipaddresses.txt'', 'a+);
fwrite($handle, $ip); fwrite($handle, "\n");
fclose($handle);
?>
All you have to do, is to make a text file and insert any of these codes or one of your
own and save it as anythingyouwant.php
Then upload it to your website and it'll do the trick :P
The Possibilities for what you can use this to are endless.
Good luck :D
This entry was posted on October 4, 2009 at 12:14 pm, and is filed under
Hacking,
Internet,
Programming
. Follow any responses to this post through RSS. You can leave a response, or trackback from your own site.
Subscribe to:
Post Comments (Atom)
Post a Comment