I am writing UserID's to a text file seperated with ||
The var $UserID
is an integer like 1, 2, 3 etc.
If a user has ID 1; the value is stored in the txt file and looks after some time like this:
1||1||1||1||1||...
What i want to achieve: if an ID is already stored in the txt file, do not store it again.
this is what i have sofar;
$UserIdtxt = $UserID."||";
$ID = explode("||", file_get_contents("user_id.txt"));
foreach($ID as $IDS) {
// here must come the check if the ID already is stored in the txt file
if($IDS != $UserID) {
file_put_contents("user_id.txt", $UserIdtxt, FILE_APPEND);
}
}
How can i make that check?