Falta un parentesis:
fwrite($fp,implode("\n",$file2)."\n".$ip
);
Y sobra un corchete:
fclose($fp);
} Código PHP:
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$file3 = "ip.txt";
if(!file_exists($file3)) {
$fp3=fopen($file3,"w");
fputs($fp3,"");
fclose($fp3);
}
$file4=file($file3);
for ($i=0;$i<count($file4);$i++) {
if ($ip == $file4[$i]) { die ("Sólo puedes votar una vez"); }
}
$fp3=fopen($file3,"w+");
fwrite($fp3,implode("\n",$file4)."\n".$ip);
fclose($fp3);
include("config.php"); //incluimos el fichero config.php donde tenemos la configuración del script
$file2=file($file); //creamos el array con las lineas del archivo
$lineas=count($file2);//contamos los elementos del array, es decir el total de lineas
$n1=$file2[0]; //asignamos a la variable el nº de votos(la línea 1 del txt)
$n2=$file2[1]; //asignamos a la variable el nº de votos(la línea 2 del txt)
$n3=$file2[2]; //asignamos a la variable el nº de votos(la línea 3 del txt)
$n4=$file2[3]; //asignamos a la variable el nº de votos(la línea 4 del txt)
if($En=="E1") //si la respuesta es la opción 1...
{$nn1=intval($n1)+1;}else{$nn1=intval($n1);} //entonces sumamos uno a $nn1, si no, se keda igual
if($En=="E2") //si la respuesta es la opción ...
{$nn2=intval($n2)+1;}else{$nn2=intval($n2);} //entonces sumamos uno a $nn2, si no, se keda igual
if($En=="E3") //si la respuesta es la opción 3...
{$nn3=intval($n3)+1;}else{$nn3=intval($n3);} //entonces sumamos uno a $nn3, si no, se keda igual
if($En=="E4") //si la respuesta es la opción 4...
{$nn4=intval($n4)+1;}else{$nn4=intval($n4);} //entonces sumamos uno a $nn4, si no, se keda igual
$fp=fopen($file,"w+"); //abrimos de nuevo el txt borrándolo todo
fwrite($fp,"$nn1\n$nn2\n$nn3\n$nn4"); //escribimos en el txt los votos.. en su respectiva línea. NOTA: \n <- cambia de línea ;)
fclose($fp); //cerramos el txt
$ntotal=$nn1+$nn2+$nn3+$nn4; //contamos el nº total de votos
?>
</p>
<table width=479 height="254" border=0 align="center" cellpadding=0 cellspacing=0>
<tr>
<td colspan=3 width=186><div align="center" class="Estilo27 Estilo34">Resultados de la encuesta</div></td>
</tr>
<tr>
<td width=186><font face=Arial><? echo $c1;?></font></td>
<td width=186><table border=0 cellpadding=0 cellspacing=1 width=67
bgcolor="#000080">
<tr>
<td width=100%><table border=0 cellpadding=0 cellspacing=0 width=<? echo $nn1*100/$ntotal;?> bgcolor=#FFFFFF
height=5>
<tr>
<td></td>
</tr>
</table></td>
</tr>
</table></td>
<td width=186><p align=center><font face=Arial size=2><? echo $nn1;?></font></p></td>
</tr>
<tr>
<td width=186><font face=Arial><? echo $c2;?></font></td>
<td width=186><table width=41% height="9" border=0 cellpadding=0 cellspacing=1
bgcolor=#000080>
<tr>
<td width=100%><table border=0 cellpadding=0 cellspacing=0 width=<? echo $nn2*100/$ntotal;?>
bgcolor=#FFFFFF height=5>
<tr>
<td></td>
</tr>
</table></td>
</tr>
</table></td>
<td width=186><p align=center><font face=Arial size=2><? echo $nn2;?></font></p></td>
</tr>
<tr>
<td width=186><font face=Arial><? echo $c3;?></font></td>
<td width=186><table border=0 cellpadding=0 cellspacing=1 width=40%
bgcolor=#000080>
<tr>
<td width=100%><table border=0 cellpadding=0 cellspacing=0 width=<? echo $nn3*100/$ntotal;?>
bgcolor=#FFFFFF height=5>
<tr>
<td></td>
</tr>
</table></td>
</tr>
</table></td>
<td width=186><p align=center><font face=Arial size=2><? echo $nn3;?></font></p></td>
</tr>
<tr>
<td width=186 colspan=3><div align="center"><span class="Estilo14 Estilo27 Estilo35">Votaciones totales </span><font face=Arial>: </font><font
color=#FFFFFF face=Arial size=2><strong><? echo $ntotal;?></strong></font></div></td>
</tr>
</table>