How can PHP be used to extract and store the IP address of a visitor accessing a specific URL with a password?

To extract and store the IP address of a visitor accessing a specific URL with a password, you can use PHP to capture the visitor's IP address and save it to a database or a file. This can be achieved by checking if the visitor has entered the correct password for the specific URL, and if so, retrieving their IP address and storing it for future reference.

<?php
// Check if the visitor has entered the correct password for the specific URL
if ($_POST['password'] == 'your_password_here') {
    // Get the visitor's IP address
    $ip_address = $_SERVER['REMOTE_ADDR'];
    
    // Store the IP address in a database or file
    // Example: storing in a text file
    $file = 'ip_addresses.txt';
    $current_data = file_get_contents($file);
    $current_data .= $ip_address . "\n";
    file_put_contents($file, $current_data);
    
    echo 'IP address stored successfully.';
} else {
    echo 'Incorrect password.';
}
?>