<?php
// Get the visitor's IP address
$visitor_ip = $_SERVER['REMOTE_ADDR'];
// Open the ip.txt file in append mode
$file = fopen('ip.txt', 'a');
// Write the IP address followed by a new line
fwrite($file, $visitor_ip . PHP_EOL);
// Close the file
fclose($file);
// Display a message
echo "Your IP address: $visitor_ip has been logged.";
?>