What potential issues can arise when trying to save the origin of users in a TXT file using PHP?

When saving the origin of users in a TXT file using PHP, potential issues can arise if the file path is not properly specified or if the file permissions do not allow writing. To solve this, ensure that the file path is correct and that the file has the necessary write permissions.

// Specify the file path where the origin of users will be saved
$file_path = 'origin.txt';

// Check if the file is writable before saving user origin
if (is_writable($file_path)) {
    // Save user origin to the file
    $user_origin = $_SERVER['REMOTE_ADDR']; // Assuming you want to save the user's IP address
    file_put_contents($file_path, $user_origin . PHP_EOL, FILE_APPEND);
    echo 'User origin saved successfully.';
} else {
    echo 'Unable to save user origin. Please check file permissions.';
}