Просмотр файла vote/index.php

Размер файла: 4.03Kb
<?php
include 'top.php';
include 'config.php';


if (!file_exists("answer.dat"))
   {
      touch("answer.dat",666);
      $aop = fopen("answer.dat","w");
      flock($aop,2);
      fputs($aop,"0|0|0|0|0");
      flock($aop,2);
      fclose($aop);
   }

if (!file_exists("ip.dat")) { touch("ip.dat",666); }
if (!file_exists("ua.dat")) { touch("ua.dat",666); }

$answer = "answer.dat";
$anf = file($answer);

$user_agent="";

if (isset($add) && isset($op))
{
  $ip = $REMOTE_ADDR;

  $fip = file("ip.dat");
  $error = null;

  for ($i=0;$i<sizeof($fip);$i++) { if ($ip == trim($fip[$i])) { $error = "1"; } }

  if (!isset($error) || empty($error) || $error != '1')
    {
        $fop = fopen("ip.dat","a");
        flock($fop,2);
        fputs($fop,"$ip\r\n");
        flock($fop,3);
        fclose($fop);
    }



  $user_agent=$_SERVER["HTTP_USER_AGENT"];

  $fua = file("ua.dat");
  $error_ua = null;

  for ($i=0;$i<sizeof($fua);$i++) { if ($user_agent == trim($fua[$i])) { $error_ua = "1"; } }

  if (!isset($error_ua) || empty($error_ua) || $error_ua != '1')
    {
        $fop = fopen("ua.dat","a");
        flock($fop,2);
        fputs($fop, getenv('HTTP_USER_AGENT')."\r\n");
        flock($fop,3);
        fclose($fop);
    }


}



if (isset($add) && isset($op) && ((isset($error) && !empty($error) && $error == '1') || (isset($error_ua) && !empty($error_ua) && $error_ua == '1')  ) ) { echo "Вы не можете голосовать 2 и более раз"; }

////////////////////////
//
if (isset($see))
{
  $file = fopen($answer,"r+t");
  $writ=fread($file,filesize($answer));
  $writ=explode("|",$writ);

     echo "<table><tr><td align=center>$name</td></tr><tr><td height=8></td></tr>";
  echo "<tr><td><input type=radio> $a1  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $writ[0]</td></tr>";
  echo "<tr><td><input type=radio> $a2 &nbsp;&nbsp;&nbsp; $writ[1]</td></tr>";
  echo "<tr><td><input type=radio> $a3 &nbsp;&nbsp;&nbsp; $writ[2]</td></tr>";
  echo "<tr><td><input type=radio> $a4  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $writ[3]</td></tr>";
  echo "<tr><td><input type=radio> $a5 &nbsp;&nbsp;&nbsp; $writ[4]</td></tr><tr><td height=8></td></tr>";

}

if (isset($add) && isset($op) && ((!isset($error) || empty($error) || $error != '1') || (!isset($error_ua) || empty($error_ua) || $error_ua != '1'))  )
{
  $file = fopen($answer,"r+t");
  $writ=fread($file,filesize($answer));
  $writ=explode("|",$writ);

  if($op == 1) { $writ[0]=$writ[0]+1; }
  if($op == 2) { $writ[1]=$writ[1]+1; }
  if($op == 3) { $writ[2]=$writ[2]+1; }
  if($op == 4) { $writ[3]=$writ[3]+1; }
  if($op == 5) { $writ[4]=$writ[4]+1; }


  echo "<table><tr><td align=center>$name</td></tr><tr><td height=8></td></tr>";
  echo "<tr><td><input type=radio> $a1  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $writ[0]</td></tr>";
  echo "<tr><td><input type=radio> $a2 &nbsp;&nbsp;&nbsp; $writ[1]</td></tr>";
  echo "<tr><td><input type=radio> $a3 &nbsp;&nbsp;&nbsp; $writ[2]</td></tr>";
  echo "<tr><td><input type=radio> $a4  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $writ[3]</td></tr>";
  echo "<tr><td><input type=radio> $a5 &nbsp;&nbsp;&nbsp; $writ[4]</td></tr><tr><td height=8></td></tr>";


  $writ=implode("|",$writ);
  rewind($file);
  fwrite($file,$writ);
  fclose($file);
}

if (!isset($add) && !isset($op) && !isset($see))
{
  echo "<table><form action=$PHP_SELF method=post>";
  echo "<tr><td align=center>$name</td></tr><tr><td height=8></td></tr>";
  echo "<tr><td><input name=op type=radio value=1> $a1</td></tr>";
  echo "<tr><td><input name=op type=radio value=2> $a2</td></tr>";
  echo "<tr><td><input name=op type=radio value=3> $a3</td></tr>";
  echo "<tr><td><input name=op type=radio value=4> $a4</td></tr>";
  echo "<tr><td><input name=op type=radio value=5> $a5</td></tr><tr><td height=8></td></tr>";
  echo "<tr><td align=center><input type=submit name=\"add\" value=\"Проголосовать\"></td></tr>";
  echo "<tr><td align=center><input type=submit name=\"see\" value=\"Результаты\"></td></tr></form>";

}

?>