<?php setcookie("login", $_POST["login"] , time()+3600, "/", "deim.etse.urv.es", 1 ); 
    $IP=$_SERVER['REMOTE_ADDR'];
    $qdate = date('Y-m-d');
    $qtime = date('H:i:s');
    $login = $_POST["login"];


    require("private/connect.inc");
    require("private/ident.inc");
    $link=Conectar();
    mysql_select_db("deim",$link);
    
    $login=addslashes($_POST["login"]);
    $pass=addslashes($_POST["pass"]);
    $result=mysql_query("SELECT login,password FROM usuaris WHERE login LIKE '$login'
    AND password=PASSWORD('$pass')");
    $row = mysql_fetch_array($result);
    if (($row["login"] != $login) || ($row == NULL)) {
      setcookie("sessio", "", time(), "/", "" );

      // Logeamos la entrada
      mysql_query("INSERT INTO log (login, ip, data, hora, login_correcte) VALUES ('$login',
      '$IP', '$qdate', '$qtime', 'false')");
    } else {
      $sessio=substr(md5(rand(0,9999999)), 0, 32);
      setcookie("sessio", $sessio, time()+900, "/", "" );
      mysql_query("UPDATE usuaris SET sessio='$sessio' WHERE login LIKE '$login'");

      //Logeamos la entrada
      mysql_query("INSERT INTO log (login, ip, data, hora, login_correcte) VALUES ('$login',
      '$IP', '$qdate', '$qtime', 'true')");
    }
    mysql_free_result($result);
  ?>
<html>
  <head>
    <link rel="stylesheet" href="estils/hoja.css" type="text/css">
    <title>Cookie</title>
    <meta http-equiv="refresh" content="0; url=login.php">
  </head>

  <body leftmargin="0" topmargin="0" bgcolor="#8F0000" OnLoad="window.location='login.php'>

  </body>
</html>

