Auriga
04-12-2005, 09:40 AM
I am using a pre-made voting script which is 99% working ok.
Except i have noticed that before you have voted there is an error in the poll.php file.
After you have voted though it disappears. Beings as it's done by IP Address (ie you can't vote more than once, i can't see the error again as it already recognises that i've voted...and don't know how to turn it off to see it again!).
It was on line 50, though, the error was.
Anyhoo here's the code...
<?
$path = __FILE__;
$path = preg_replace( "'\\\poll\.php'", "", $path);
$path = preg_replace( "'/poll\.php'", "", $path);
include($path."/poll_config.php");
include($path."/js_header.php");
$dir = dir($path."/polldata"); //Create a directory object to the current directory
$polls = array();
$ids = array();
$delete = array("poll_",".txt");
$i = 0;
while($dir_entry = $dir->read()){
if(strstr($dir_entry,"poll")){
$polls[$i] = $dir_entry;
$id = str_replace($delete, "", $dir_entry);
$ids[$i] = $id;
$i++;
}
}
if($i == 0){
echo "<b>".$nopoll."</b>";
}
else{
if($random_display){
srand((double)microtime()*1000000);
$pollid = rand(0,count($polls)-1);
}
else{
if(isset($_GET['showpoll'])){
$pollid = $_GET['showpoll'];
if(empty($polls[$pollid])) $pollid = 0;
}
else{
if(!isset($_POST['pollid'])) $pollid = 0;
else $pollid = intval($_POST['pollid']);
}
}
$pollfile = $path."/polldata/".$polls[$pollid];
$ipfile = $path."/polldata/ips_".$ids[$pollid].".php";
include($pollfile);
if(isset($_POST['vote'])){
include("submit_vote.php");
submitVote($_POST['vote']);
}
else{ // check that they have voted or not
$ip = fopen($ipfile, "r");
$contents = fread($ip, filesize($ipfile));
$uip = $_SERVER['REMOTE_ADDR'];
// start html code returning results.....................................
if(stristr($contents,$uip) !== false){
$ask = stripslashes($ask);
echo "<b>$ask</b><br>";
if(isset($_GET['voted'])) echo "Thank you for your vote";
else echo "$voted_already";
echo "<br><br>$total ";
if($total == "1") echo "Vote";
else echo "Votes";
echo "\n\n";
for($i=0;$i<count($a);$i++){
$a[$i] = stripslashes($a[$i]);
if($a[$i] != "" && $v[$i] != ""){
$percentage = (round(($v[$i] / $total) * 100, 1));
echo "<br><b>$a[$i]</b> (<span id=\"ans_".$i."\" style=\"cursor:help;\" title=\"".$a[$i]." - ".$v[$i]." votes (".$percentage."%)\">".$v[$i]."</span>)<br>\n";
echo "<img alt=\"$a[$i] - $v[$i] votes ($percentage%)\" style=\"cursor:help;\" src=\"$imgurl\" height=\"".$poll_bar_height."\" width=";
echo (round(($v[$i] / $total) * 80, 0));
echo ">";
}
}
echo "<br><br>";
if(!$random_display) printNextPoll($pollid);
}
else{
$ask = stripslashes($ask);
echo "<b>$ask</b><br>\n\n";
echo "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']."\">\n\n";
echo "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n";
for($i = 0;$i< count($a);$i++){
$a[$i] = stripslashes($a[$i]);
if($a[$i] != ""){
echo " <tr>\n";
echo " <td>\n";
echo " <input type=\"radio\" name=\"vote\" value=\"$a[$i]\">\n";
echo " </td>\n";
echo " <td>";
echo "$a[$i]";
echo "</td>\n";
echo " </tr>\n";
}
}
echo "</table>\n\n";
echo "<input type=\"hidden\" name=\"pollid\" value=\"$pollid\">\n";
echo "<input type=\"hidden\" name=\"pollpid\" value=\"$ids[$pollid]\">\n";
echo "<input type=\"submit\" value=\"$vote_button_text\">\n";
echo "</form>\n\n";
if(!$random_display) printNextPoll($pollid);
}
}
}
// Please, please, please keep this line intact to spread the word about the FREE CJ Dynamic Poll - Thank you : )
echo "<br><A HREF=\"javascript:loadPopupPollArchive()\"><small>$view_archive</small></A>";
function printNextPoll($pollid){
global $path;
$nextpoll = $pollid + 1;
$prevpoll = $pollid - 1;
$dir = dir($path."/polldata"); //Create a directory object to the current directory
$polls = array();
$i = 0;
while($dir_entry = $dir->read()){
if(strstr($dir_entry,"poll")){
$polls[$i] = $dir_entry;
$i++;
}
}
if(!empty($polls[$prevpoll])) echo "<small><A HREF=\"".$_SERVER['PHP_SELF']."?showpoll=$prevpoll\"><< Prev</A> </small>";
if(!empty($polls[$nextpoll])) echo "<small><A HREF=\"".$_SERVER['PHP_SELF']."?showpoll=$nextpoll\">Next >></A></small>";
}
?>
Actually i think the error was on this line...
$contents = fread($ip, filesize($ipfile));
Can anyone tell me what's wrong and how to fix it?
Here the site it's on...clicky clicky (www.auriga.org.uk)
Except i have noticed that before you have voted there is an error in the poll.php file.
After you have voted though it disappears. Beings as it's done by IP Address (ie you can't vote more than once, i can't see the error again as it already recognises that i've voted...and don't know how to turn it off to see it again!).
It was on line 50, though, the error was.
Anyhoo here's the code...
<?
$path = __FILE__;
$path = preg_replace( "'\\\poll\.php'", "", $path);
$path = preg_replace( "'/poll\.php'", "", $path);
include($path."/poll_config.php");
include($path."/js_header.php");
$dir = dir($path."/polldata"); //Create a directory object to the current directory
$polls = array();
$ids = array();
$delete = array("poll_",".txt");
$i = 0;
while($dir_entry = $dir->read()){
if(strstr($dir_entry,"poll")){
$polls[$i] = $dir_entry;
$id = str_replace($delete, "", $dir_entry);
$ids[$i] = $id;
$i++;
}
}
if($i == 0){
echo "<b>".$nopoll."</b>";
}
else{
if($random_display){
srand((double)microtime()*1000000);
$pollid = rand(0,count($polls)-1);
}
else{
if(isset($_GET['showpoll'])){
$pollid = $_GET['showpoll'];
if(empty($polls[$pollid])) $pollid = 0;
}
else{
if(!isset($_POST['pollid'])) $pollid = 0;
else $pollid = intval($_POST['pollid']);
}
}
$pollfile = $path."/polldata/".$polls[$pollid];
$ipfile = $path."/polldata/ips_".$ids[$pollid].".php";
include($pollfile);
if(isset($_POST['vote'])){
include("submit_vote.php");
submitVote($_POST['vote']);
}
else{ // check that they have voted or not
$ip = fopen($ipfile, "r");
$contents = fread($ip, filesize($ipfile));
$uip = $_SERVER['REMOTE_ADDR'];
// start html code returning results.....................................
if(stristr($contents,$uip) !== false){
$ask = stripslashes($ask);
echo "<b>$ask</b><br>";
if(isset($_GET['voted'])) echo "Thank you for your vote";
else echo "$voted_already";
echo "<br><br>$total ";
if($total == "1") echo "Vote";
else echo "Votes";
echo "\n\n";
for($i=0;$i<count($a);$i++){
$a[$i] = stripslashes($a[$i]);
if($a[$i] != "" && $v[$i] != ""){
$percentage = (round(($v[$i] / $total) * 100, 1));
echo "<br><b>$a[$i]</b> (<span id=\"ans_".$i."\" style=\"cursor:help;\" title=\"".$a[$i]." - ".$v[$i]." votes (".$percentage."%)\">".$v[$i]."</span>)<br>\n";
echo "<img alt=\"$a[$i] - $v[$i] votes ($percentage%)\" style=\"cursor:help;\" src=\"$imgurl\" height=\"".$poll_bar_height."\" width=";
echo (round(($v[$i] / $total) * 80, 0));
echo ">";
}
}
echo "<br><br>";
if(!$random_display) printNextPoll($pollid);
}
else{
$ask = stripslashes($ask);
echo "<b>$ask</b><br>\n\n";
echo "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']."\">\n\n";
echo "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n";
for($i = 0;$i< count($a);$i++){
$a[$i] = stripslashes($a[$i]);
if($a[$i] != ""){
echo " <tr>\n";
echo " <td>\n";
echo " <input type=\"radio\" name=\"vote\" value=\"$a[$i]\">\n";
echo " </td>\n";
echo " <td>";
echo "$a[$i]";
echo "</td>\n";
echo " </tr>\n";
}
}
echo "</table>\n\n";
echo "<input type=\"hidden\" name=\"pollid\" value=\"$pollid\">\n";
echo "<input type=\"hidden\" name=\"pollpid\" value=\"$ids[$pollid]\">\n";
echo "<input type=\"submit\" value=\"$vote_button_text\">\n";
echo "</form>\n\n";
if(!$random_display) printNextPoll($pollid);
}
}
}
// Please, please, please keep this line intact to spread the word about the FREE CJ Dynamic Poll - Thank you : )
echo "<br><A HREF=\"javascript:loadPopupPollArchive()\"><small>$view_archive</small></A>";
function printNextPoll($pollid){
global $path;
$nextpoll = $pollid + 1;
$prevpoll = $pollid - 1;
$dir = dir($path."/polldata"); //Create a directory object to the current directory
$polls = array();
$i = 0;
while($dir_entry = $dir->read()){
if(strstr($dir_entry,"poll")){
$polls[$i] = $dir_entry;
$i++;
}
}
if(!empty($polls[$prevpoll])) echo "<small><A HREF=\"".$_SERVER['PHP_SELF']."?showpoll=$prevpoll\"><< Prev</A> </small>";
if(!empty($polls[$nextpoll])) echo "<small><A HREF=\"".$_SERVER['PHP_SELF']."?showpoll=$nextpoll\">Next >></A></small>";
}
?>
Actually i think the error was on this line...
$contents = fread($ip, filesize($ipfile));
Can anyone tell me what's wrong and how to fix it?
Here the site it's on...clicky clicky (www.auriga.org.uk)