unsider Posted April 9, 2008 Share Posted April 9, 2008 Alright, I've written a poll that allows you to vote once, retreiving your IP and logging it into a .dat file. Well upon loading of the 'index' I am iterating an IF statement to determine whether to display the poll choices, or the poll results based on the IP you are viewing the page with. All of my functions are operational, 'has_voted', and 'the_current_poll_results' Problem: I would like to display my the_current_poll_results(); function. Although it continues to display my (show_vote_control('1' ); function. As well as $ipaddress, so everything is outputting. I fear the problem may be in my syntax somewhere, but I can't for the life of me find it. Everything seems like it should work, although I'm still having problems. If you need any more code, questions, etc.. let me know. index.php <?php require_once('backendfunctions.php'); $ipaddress = $_SERVER['REMOTE_ADDR']; global $PREVENT_DUPLICATE_VOTES; if($PREVENT_DUPLICATE_VOTES && has_voted($poll_id, $ipaddress)) { the_current_poll_results(); } else { echo "$ipaddress"; show_vote_control('1'); show_vote_control('2'); } ?> List of functions: backendfunctions.php <?php $PREVENT_DUPLICATE_VOTES = TRUE; function vote_history_add($poll_id, $ipaddress, $vote_value_id) { $history_fp = @fopen(vote_history_file_path($poll_id), "a"); if($history_fp === FALSE) { die("Unable to open history file for writing"); } @flock($history_fp, LOCK_EX); fputs($history_fp, $ipaddress . "|" . $vote_value_id . "\n"); fclose($history_fp); } function explode_history($line) { return array_map("trim", explode("|", $line)); } function vote_history_list($poll_id) { // Load existing vote history $summarylist = @file(vote_history_file_path($poll_id)); if($summarylist !== FALSE) { $summarylist = array_map("explode_history", $summarylist); } return $summarylist; } function has_voted($poll_id, $ipaddress) { $vote_history_list = vote_history_list($poll_id); if($vote_history_list !== FALSE) { return( find_vote_history(trim($ipaddress), $vote_history_list) !== FALSE ); } else { return FALSE; } } function find_vote_history($ipaddress, $list) { if(!empty($list)) { for($i = 0; $i < count($list); $i++) { if($list[$i][0] == $ipaddress) return $list[$i]; } } return FALSE; } ?> Quote Link to comment Share on other sites More sharing options...
Cosizzle Posted April 9, 2008 Share Posted April 9, 2008 omg... clean code I'm gonna take another look at your code (not saying i know what it is haha) But I noticed that in your backendfunctions.php in you're first if statement there were 3 '===' if($history_fp === FALSE) { die("Unable to open history file for writing"); } Perhaps this is why? Just a shot in the dark i saw quickly Quote Link to comment Share on other sites More sharing options...
unsider Posted April 9, 2008 Author Share Posted April 9, 2008 Discovered an error somewhere else in my backend script. Probably should have looked a little harder. Quote Link to comment Share on other sites More sharing options...
Cosizzle Posted April 9, 2008 Share Posted April 9, 2008 were the three === supposed to be there? Quote Link to comment Share on other sites More sharing options...
discomatt Posted April 9, 2008 Share Posted April 9, 2008 === is EXACTLY and is fine. Cosizzle, try this: <?php $var = FALSE; if ($var == 0) echo '$var == 0<br>'; if ($var === 0) echo '$var === 0<br>'; ?> === FALSE is very handy on functions that may return 0, but have not actually failed Quote Link to comment Share on other sites More sharing options...
Cosizzle Posted April 9, 2008 Share Posted April 9, 2008 :-\ hmm - I have never not once seen === used at least not that I can recall. Thanks for the tip! Quote Link to comment Share on other sites More sharing options...
unsider Posted April 9, 2008 Author Share Posted April 9, 2008 :-\ hmm - I have never not once seen === used at least not that I can recall. Thanks for the tip! Glad he helped you understand, saved me from writing up a little demo . Glad you learned something from it though. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.