I want to check if a string exists within a text file and if it exists, return the message string exists. If it does not exist, add the string to the file and return string added.
I got it working with no message:
<?php
$path = '../test/usersBlacklist.txt';
$input = $_POST["id"];
if ($input) {
    $handle = fopen($path, 'r+');
    while (!feof($handle)) {
        $value = trim(fgets($handle));
        if ($value == $input) {
            return false;
        }
    }
    fwrite($handle, $input);
    fclose($handle);
    return true;
}
if (true) {
    echo 'added';
} else {
    echo 'exists';
}
?>
 
     
    