37 lines
1.1 KiB
PHP
37 lines
1.1 KiB
PHP
|
<!doctype html>
|
||
|
<html>
|
||
|
<head>
|
||
|
<meta charset="utf-8">
|
||
|
<title>PHP External IP Address Finder</title>
|
||
|
</head>
|
||
|
<body>
|
||
|
<?php
|
||
|
// User definable varibales
|
||
|
// Set save_to_file = "TRUE" to write the IP address
|
||
|
// hostname, and date to a text file
|
||
|
// timezone - should be the timezone where the server is located
|
||
|
// filename - text file for storing the IP, hostname and date. By default ipaddress.txt
|
||
|
|
||
|
$save_to_file = "TRUE";
|
||
|
$timezone = 'America/New_York';
|
||
|
$filename = "ipaddress.txt";
|
||
|
|
||
|
|
||
|
$address = $_SERVER['REMOTE_ADDR'];
|
||
|
$hostname = gethostbyaddr($address);
|
||
|
date_default_timezone_set($timezone);
|
||
|
$dateandtime = date(DATE_RFC822);
|
||
|
$writeout = "IP Address: " . $address . "<br>" . "Hostname: " . $hostname . "<br>" . "Last update: " . $dateandtime;
|
||
|
echo $writeout;
|
||
|
|
||
|
if ($save_to_file == "TRUE") {
|
||
|
|
||
|
$ipFileHandler = fopen($filename, 'w') or die("<br>ERROR CREATING FILE. CHECK DIRECTORY PERMISSIONS<br>");
|
||
|
fwrite($ipFileHandler, "IP Address: " . $address . "\n" . "Hostname: " . $hostname . "\n" . "Last update: " . $dateandtime);
|
||
|
fclose($ipFileHandler);
|
||
|
}
|
||
|
|
||
|
?>
|
||
|
</body>
|
||
|
</html>
|