<?php
require( "open_db.php" );

session_name( "INFDJwebsite" );
	$v1="user_id";
	$v2="user_nick";
	$v3="user_auth";
	$v4="user_usaCorreo";
	$v5="user_level";
	session_register($v1,$v2,$v3,$v4,$v5);
session_start();

$action="";
if ( isset( $db_login ) && isset( $db_pass ) )
{
 checkUser( $db_login, $db_pass, $db_autolog );
 if ( !$user_auth )
   $action = "?go=../registro/epassword.htm";
}

mysql_close($conexion);

header("Location:../$action\n\n");

function checkUser( $user, $pass, $rem )
{
  global $conexion, $id, $user_auth, $user_nick, $user_id, $user_usaCorreo, $user_level;
  $dev = false;

  $consulta = "SELECT id, level, usaCorreo FROM users WHERE nick = '$user' AND pass='$pass'";
	$res = mysql_query( $consulta, $conexion ) OR die("No puedo realizar la consulta");
	if (  mysql_num_rows($res) > 0 )
	{
 	  $user_id = mysql_result( $res, 0, "id" );
	  $user_nick = $user;
	  $user_auth = true;
	  $user_usaCorreo = mysql_result( $res, 0, "usaCorreo" );
	  $user_level = mysql_result( $res, 0, "level" );
	  mysql_query( "UPDATE users SET ultimaEntrada=NOW() WHERE id=$user_id", $conexion ) OR die("No puedo actualizar tu ficha");
	  if ( $rem )
	  {
	    setcookie( "ulogin", "$user", time()+2592000, "/", ".infdj.com" );
	    setcookie( "upass", "$pass", time()+2592000, "/", ".infdj.com" );
	  }
	  $dev = true;
	}
	mysql_free_result($res);
 return $dev;
}
?>