Hey all,
I have a little problem with a script I am writing. It's a voting script with a weekly poll. Users can vote once per week. I want it to record the user who voted. I tried this, but it just seems to write the \n part:
// Log who voted
$user = $_SESSION['user'];
$vf = fopen("voted.txt",'a');
fwrite($vf,"$user\n");
fclose($vf);
And I would like to know how I can have my script check if a user voted already. The username is stored in a session string $_SESSION['user']. I tried this but it doesn't seem to do anything at all:
// Voting allowed user logged in, check if already voted
$vc = fopen("voted.txt",'r');
while ($scan = fscanf($vc, $_SESSION['user'])) {
echo "You already voted.";
exit;
}
Any suggestions more then welcome 🙂
P.S. I don't have an SQL database available, so please don't come with database solutions, thanks.