What is the purpose of using a text file to store and update the IP address in a PHP script?

Using a text file to store and update the IP address in a PHP script allows for easy retrieval and modification of the IP address without having to modify the PHP code itself. This can be useful for dynamically updating the IP address without needing to redeploy the code. By reading and writing the IP address from a text file, the PHP script can easily access the most up-to-date IP address.

// Read the current IP address from the text file
$ipFile = 'ip_address.txt';
$currentIP = file_get_contents($ipFile);

// Update the IP address in the text file
$newIP = '127.0.0.1'; // New IP address to update
file_put_contents($ipFile, $newIP);

// Use the IP address in the PHP script
echo "Current IP address: " . $currentIP;