<?php
session_start();
$info="";
 if(isset($_POST['mail']))
   {
     $_POST['mail']=trim($_POST['mail']);
     $_POST['pas']=trim($_POST['pas']);

     if($_POST['mail']!="" && $_POST['pas']!="")
        {
          $d=opendir("ac");
          while(($e=readdir($d))!=false)
           {
             if($e =="." || $e ==".." || $e==".htaccess" || $e=="sess") continue;
             $w=file("ac/$e");
             if(md5($_POST['pas'])==$w[0])
               {
                  $w=file("cons/$e");
                  $expl=explode("*",$w[0]);
                  $expl[1]=trim($expl[1]);
                  if($expl[1]==$_POST['mail'])
                     {
                       	$f=fopen("ac/sess","a+");
                     	fwrite($f,time()."*".session_id()."*".$e."*".$expl[0]."\r\n");
                     	fclose($f);
                     	echo "<meta http-equiv=refresh content='0; url=admin1.php?sel1=selected'>";
                        exit();
                     }
               }
           }
          closedir($d);
          $info="<font color=red>Неверные e-mail, или пароль!</font>";
        }
   }

  //Очистка
                        $w=file("ac/sess");
                        $f=fopen("ac/sess","w");
                        foreach($w as $line)
                         {
                           $expl=explode("*",$line);
                           if((time()-$expl[0])>7200)continue;
                           fwrite($f,$line);
                         }
                     	fclose($f);
?>
<!DOCTYPE html>
<html>
	<head>
	<meta charset="utf-8" />
  <title>Вход для консультантов</title>

<style>
  h2
         {
          font-family: Arial, sans-serif;
          font-size:12pt;
          color:#408080;

         }
  table {
         font-family: Arial, sans-serif;
         font-size:10pt;
          color:#5C5C5C;
 	     font-size:11pt;
      }
  #button {

       font-family:"Times New Roman", "serif";
       color:#408080;
       font-size:9pt;
       background-color:#C0C0C0;
      font-weight:600;
      text-align:center;
      width:60px;
      }
</style>
</head>

<body>

<center>
<table CELLPADDING=10 CELLSPACING=10 width=35%><tr><td >
 <table align=center >
    <tr><td ><h2>Вход для консультантов</h2>
              <form action="index.php" method="post">
               <?php echo $info ?><br />
               e-mail<br />
               <input name="mail" type="text" size=20><br >
               пароль<br />
               <input name="pas" type="password" size=20><br /><br />
               <input type="submit" value="Вход" id=button><br /><br /><br />
              </form>
			  <br /><br /><br /><br /><br/><br/><a target="_blank" href=../admin4.php>Вход для администратора</a><br /><br />
    </td></tr>
 </table>
</td></tr></table>
</center>
</body>
</html>


