<?php
session_start();
include_once('db_config_hosting.php');

$_SESSION["user"] = $User = isset($_POST['ftuser']) ? $_POST["ftuser"]  : ""; 
$_SESSION["passwd"] = $Passwd = isset($_POST['ftpasswd']) ? $_POST['ftpasswd'] : "";
$Remember = isset($_POST['fremember']) ? $_POST['fremember'] : "";
if( $Remember == true ) {
   setcookie("012119", $user, time()+(3600*24*365));
   setcookie("012120", $passwd, time()+(3600*24*365));
}

if( $User != "" && $Passwd != "" ) {

   $sql = "select sql_no_cache usuario, clave, panel, informes, admin from usuarios where usuario='" . $User . "' and clave='" . $Passwd . "'";
   $result = $conn->query($sql);
   if ($result->num_rows > 0) {
      if( $Remember == true ) {
         setcookie("012119", $User,  time() + (86400 * 365), "/" );
         setcookie("012120", $Passwd,  time() + (86400 * 365), "/" );
      }
   
      $panel = "0";
      if($row = $result->fetch_assoc()) {
          $_SESSION["admin"] = $row["admin"];
          $_SESSION["panel"] = $panel = $row["panel"];
          $_SESSION["informes"] = $panel = $row["informes"];
      }
      if( is_resource($result) ) mysql_free_result( $result );
      if( $panel == "1" ) header("Location: traficoPanel.php");
      else header("Location: traficoIndex.php");
   }
   else {
      setcookie("012119", "", time() - 3600);
      setcookie("012120", "", time() - 3600);
      session_unset(); 
      mysqli_close($conn);
      header("Location: traficoIndex.php");
   }
}
?>


