Jump to content

[SOLVED] Help


unsider

Recommended Posts

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;

}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/100253-solved-help/
Share on other sites

:o 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

Link to comment
https://forums.phpfreaks.com/topic/100253-solved-help/#findComment-512595
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.