apostel
Gebruiker
- Lid geworden
- 16 mei 2002
- Berichten
- 721
Hallo allemaal
Ben er dus zelf aan begonnen voor een script te maken in php voor een poll.
Maar heb al verschillende problemen
1 - hoe kan ik van iedere persoon het percentage yes en no laten zien ?
2 -hoe bescherm ik deze dan nog dmv dat ze niet meer als 1 keer kunnen stemmen .
Zal jullie eeuwig dankbaar zijn
Hier me poll.php script
<?
$aantalDecimalen=1;
$totaal=0;
function getStand($nr) {
global $totaal, $st, $aantalDecimalen;
if ( $totaal == "" ){
return 0;
}
$procent=$st[$nr]/$totaal*100;
for ($i=0;$i<$aantalDecimalen;$i++) {
$procent *= 10;
}
$procent=(int)($procent+0.5);
for ($i=0;$i<$aantalDecimalen;$i++) {
$procent /= 10;
}
return $procent;
}
function reedsGestemd() {
$log=fopen("log.txt","r");
while ( !feof($log) ) {
$ips[]=trim(fgets($log,20));
}
fclose($log);
if ( in_array(getenv("REMOTE_ADDR"),$ips) ){
return true;
} else {
return false;
}
}
?>
<HTML>
<HEAD>
<TITLE>Poll</TITLE>
</HEAD>
<BODY class="bged">
<?
if ( $stand==1 ){
$bestand=fopen("stand.txt","r");
for ( $i=0;$i>=0;$i++ ) {
$dummy=trim(fgets($bestand,10));
if ( feof($bestand) ){
break;
}
$totaal+=($st[$i]=($dummy==""?0:$dummy));
}
fclose($bestand);
if ( $submit=="Stem" && ($meerdere_stemmen==1 || !reedsGestemd())){
$st[$poll]=($st[$poll]!=""?$st[$poll]+1:1);
$totaal++;
$bestand=fopen("stand.txt","w");
$dummy=array_keys($st);
rsort($dummy);
for ( $i=0;$i<=$dummy[0];$i++ ) {
fputs($bestand,$st[$i]."\n");
}
fclose($bestand);
$log=fopen("log.txt","a");
fputs($log,getenv("REMOTE_ADDR")."\n");
fclose($log);
}
?>
<P>De stand van de poll is als volgt:</P>
<P><TABLE border="0" style="border-width: 0;">
<TR><TD>Optie 1:</TD><TD align="right"><? echo getStand(0); ?> %</TD><TD><IMG src="/stand.gif" height="14" width="<? echo getStand(0); ?>"></TD></TR>
<TR><TD>Optie 2:</TD><TD align="right"><? echo getStand(1); ?> %</TD><TD><IMG src="/stand.gif" height="14" width="<? echo getStand(1); ?>"></TD></TR>
</TABLE></P>
<P>Aantal stemmen: <? echo $totaal; ?></P>
<?
} else {
?>
<P>Absa</P>
<P><FORM action="poll.php" method="GET">
<INPUT type="hidden" name="stand" value="1">
<INPUT type="radio" name="poll" value="0" checked="true">Yes<BR>
<INPUT type="radio" name="poll" value="1">No<BR>
</FORM></P>
<? } ?>
<P>Gorasonas</P>
<P><FORM action="poll.php" method="GET">
<INPUT type="hidden" name="stand" value="1">
<INPUT type="radio" name="poll" value="0" checked="true">Yes<BR>
<INPUT type="radio" name="poll" value="1">No<BR>
</FORM></P>
<? } ?>
<P>Matrix</P>
<P><FORM action="poll.php" method="GET">
<INPUT type="hidden" name="stand" value="1">
<INPUT type="radio" name="poll" value="0" checked="true">Yes<BR>
<INPUT type="radio" name="poll" value="1">No<BR>
<P><INPUT type="submit" name="submit" value="Stem"><FONT size="-1"> (1x klikken)</FONT>
</FORM></P>
<? } ?>
</BODY>
</HTML>
Ben er dus zelf aan begonnen voor een script te maken in php voor een poll.
Maar heb al verschillende problemen

1 - hoe kan ik van iedere persoon het percentage yes en no laten zien ?
2 -hoe bescherm ik deze dan nog dmv dat ze niet meer als 1 keer kunnen stemmen .
Zal jullie eeuwig dankbaar zijn

Hier me poll.php script
<?
$aantalDecimalen=1;
$totaal=0;
function getStand($nr) {
global $totaal, $st, $aantalDecimalen;
if ( $totaal == "" ){
return 0;
}
$procent=$st[$nr]/$totaal*100;
for ($i=0;$i<$aantalDecimalen;$i++) {
$procent *= 10;
}
$procent=(int)($procent+0.5);
for ($i=0;$i<$aantalDecimalen;$i++) {
$procent /= 10;
}
return $procent;
}
function reedsGestemd() {
$log=fopen("log.txt","r");
while ( !feof($log) ) {
$ips[]=trim(fgets($log,20));
}
fclose($log);
if ( in_array(getenv("REMOTE_ADDR"),$ips) ){
return true;
} else {
return false;
}
}
?>
<HTML>
<HEAD>
<TITLE>Poll</TITLE>
</HEAD>
<BODY class="bged">
<?
if ( $stand==1 ){
$bestand=fopen("stand.txt","r");
for ( $i=0;$i>=0;$i++ ) {
$dummy=trim(fgets($bestand,10));
if ( feof($bestand) ){
break;
}
$totaal+=($st[$i]=($dummy==""?0:$dummy));
}
fclose($bestand);
if ( $submit=="Stem" && ($meerdere_stemmen==1 || !reedsGestemd())){
$st[$poll]=($st[$poll]!=""?$st[$poll]+1:1);
$totaal++;
$bestand=fopen("stand.txt","w");
$dummy=array_keys($st);
rsort($dummy);
for ( $i=0;$i<=$dummy[0];$i++ ) {
fputs($bestand,$st[$i]."\n");
}
fclose($bestand);
$log=fopen("log.txt","a");
fputs($log,getenv("REMOTE_ADDR")."\n");
fclose($log);
}
?>
<P>De stand van de poll is als volgt:</P>
<P><TABLE border="0" style="border-width: 0;">
<TR><TD>Optie 1:</TD><TD align="right"><? echo getStand(0); ?> %</TD><TD><IMG src="/stand.gif" height="14" width="<? echo getStand(0); ?>"></TD></TR>
<TR><TD>Optie 2:</TD><TD align="right"><? echo getStand(1); ?> %</TD><TD><IMG src="/stand.gif" height="14" width="<? echo getStand(1); ?>"></TD></TR>
</TABLE></P>
<P>Aantal stemmen: <? echo $totaal; ?></P>
<?
} else {
?>
<P>Absa</P>
<P><FORM action="poll.php" method="GET">
<INPUT type="hidden" name="stand" value="1">
<INPUT type="radio" name="poll" value="0" checked="true">Yes<BR>
<INPUT type="radio" name="poll" value="1">No<BR>
</FORM></P>
<? } ?>
<P>Gorasonas</P>
<P><FORM action="poll.php" method="GET">
<INPUT type="hidden" name="stand" value="1">
<INPUT type="radio" name="poll" value="0" checked="true">Yes<BR>
<INPUT type="radio" name="poll" value="1">No<BR>
</FORM></P>
<? } ?>
<P>Matrix</P>
<P><FORM action="poll.php" method="GET">
<INPUT type="hidden" name="stand" value="1">
<INPUT type="radio" name="poll" value="0" checked="true">Yes<BR>
<INPUT type="radio" name="poll" value="1">No<BR>
<P><INPUT type="submit" name="submit" value="Stem"><FONT size="-1"> (1x klikken)</FONT>
</FORM></P>
<? } ?>
</BODY>
</HTML>
Laatst bewerkt: