I'm setting up a polling system where voters can only vote once, based on their IP address.
When the poll loads I want to open the text file with the list of blocked IPs to see if a voter has already voted. If not, they vote and then their IP should get added to the array and then the updated array get written back to the text file.
Here's the code I have so far:
I think I have it worked out until the point where I need to write the updated array, and then it's not working.
Thanks!
When the poll loads I want to open the text file with the list of blocked IPs to see if a voter has already voted. If not, they vote and then their IP should get added to the array and then the updated array get written back to the text file.
Here's the code I have so far:
Code:
<?php // Get information from file // $IPs = "IPs.txt"; $fp = fopen($IPs, "r"); $ipList = fread($fp, filesize($IPs)); fclose($fp); // Explode line breaks // $bannedIPs = explode("\n", $ipList); // Check for IP // if (in_array($ipNew, $ipList)) { echo "Thanks! We've already counted your vote."; } else { include("voteCode.php"); } // Get new IP // $ipNew = $REMOTE_ADDR; echo "Your IP: " . $ipNew . "<br />"; // Add new IP to array // $bannedIPs[] = $ipNew; // Write new array & close file // $fp = fopen("IPs.txt","w+"); foreach($bannedIPs as $key => $value){ fwrite($fp,$value."\n"); } fclose($fp); ?>
Thanks!
Comment