getting the IP address
Moderator: General Moderators
getting the IP address
hi, i have a small problam i was wondering if any one could be so kind as to tell me if there is some way in which i can use PHP to retrive the ip address of all visitors to my site, and some how send this data to a txt file ?? i would really be greatfull if some one could help.
THANKS!
THANKS!
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
Create test.txt before using this.
Read it, lookup the functions and learn.
Read it, lookup the functions and learn.
Code: Select all
<?php
$filename = 'test.txt';
$ip = $_SERVER['REMOTE_ADDR']."\n";
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $ip to our opened file.
if (!fwrite($handle, $ip)) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote $ip to file $filename";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
?>