Support Forums
[Tutorial] How to grab IP adress with PHP - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: PHP The Hypertext Preprocessor (https://www.supportforums.net/forumdisplay.php?fid=21)
+---- Thread: [Tutorial] How to grab IP adress with PHP (/showthread.php?tid=4154)

Pages: 1 2 3


[Tutorial] How to grab IP adress with PHP - flAmingw0rm - 01-03-2010

Hello Support Forums,

In this tutorial I will show you how to grab someone's IP Adress when they visit a website.


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 Code:
<?php 
print ($_SERVER['REMOTE_ADDR'], "I'm Watching You!"); 
?>

Printing it to a File:

PHP Code:
<?php 
$ip 
$_SERVER['REMOTE_ADDR']; 
$handle fopen('ipaddresses.txt'', 'a+); 
fwrite($handle$ip); fwrite($handle"\n"); 
fclose($handle); 
?>

Now, you have to make a new text file and insert any of these codes or your own and save it as "anything.php".

Good luck. Smile

-Risto


RE: [Tutorial] How to grab IP adress with PHP - Treblez - 01-03-2010

yes this could save a lot of hassle - i was looking for something similar - thanks!


RE: [Tutorial] How to grab IP adress with PHP - Gaijin - 01-03-2010

Good and easy....
But you should really remove the use of the second fwrite()

PHP Code:
fwrite($handle"{$ip}\n"); 



RE: [Tutorial] How to grab IP adress with PHP - Nyx- - 01-03-2010

(01-03-2010, 09:40 AM)Master of The Universe Wrote: Good and easy....
But you should really remove the use of the second fwrite()

PHP Code:
fwrite($handle"{$ip}\n"); 

does the {} get printed also? i mean wouldnt the best way just be fwrite($handle, $ip . "\n");


RE: [Tutorial] How to grab IP adress with PHP - Gaijin - 01-03-2010

(01-03-2010, 09:31 PM)Nyx- Wrote: does the {} get printed also? i mean wouldnt the best way just be fwrite($handle, $ip . "\n");

No...
That's useful when you want to use a variable within a string....

PHP Code:
echo "This will print {$var}s and add s on the end :D..."

But your way is also fine, I just like the looks of {}..


RE: [Tutorial] How to grab IP adress with PHP - Qkyrie - 01-09-2010

nice and easy tutorial, I use a similar one to check logs on my website.


RE: [Tutorial] How to grab IP adress with PHP - Psycho - 01-12-2010

Code:
$handle = fopen('ipaddresses.txt'', 'a+);

should be

Code:
$handle = fopen('ipaddresses.txt', 'a+');



RE: [Tutorial] How to grab IP adress with PHP - flAmingw0rm - 03-06-2010

(01-12-2010, 07:02 AM)Psycho Wrote:
Code:
$handle = fopen('ipaddresses.txt'', 'a+);

should be

Code:
$handle = fopen('ipaddresses.txt', 'a+');

I can't edit my thread anymore. Anyway, thank you. Smile


RE: [Tutorial] How to grab IP adress with PHP - TheLifelessOne - 03-12-2010

How would you exclude a specific IP from being detected?


RE: [Tutorial] How to grab IP adress with PHP - Kewlz - 04-06-2010

Good TUT bro
thanks