Help with login, the session does not take me

0

I work with MVC and I put a condition in the call to the roadmap, where if the user is not in the session, he / she calls the login, that is, you can not enter any driver without being logged in:

<?php
session_start();
require_once ($_SERVER['DOCUMENT_ROOT'].'/gestionweb/routes.php');
require_once('routes.php');

if (isset($_SESSION['usuario'])){
    require_once ($_SERVER['DOCUMENT_ROOT'].'/gestionweb/views/template.php');
if (isset($_REQUEST['id'])){
    $id=$_REQUEST['id'];

}else{
$id=0;}

	if (isset($_GET['controller'])&&isset($_GET['action'])) {
		$controller=$_GET['controller'];
		$action=$_GET['action'];
   
        call($controller,$action,$id);		
	}
}else{
    echo "no existe";
    call("login","index",0);
}
?>
Of the security I'm going to order later, I want the session to work for me. The fact is that it always redirects to the login:

<?php
require_once ("C:\xampp\htdocs\gestionweb\includes\claseConexion.php");

class Login{
  private $estado;
  private $idp;

public function __construct(){
  
   } 

public function User($usuario,$pass)
	{
		try
		{
            $conexion = Conexion::singleton_conexion();
			

			$stm=$conexion->prepare("SELECT * FROM despensa.usuarios WHERE nombre='".$usuario."' AND pass='".$pass."';");
		      
              $stm->execute();
           $array=$stm->fetchAll(PDO::FETCH_ASSOC);
           
           if ($array>0){ 
                foreach ($array as $n){
                  
                session_start();
            $_SESSION['usuario']=$n['nombre']; 
            $_SESSION['idlog']=$n['iduser'];        
                }
            
           }
			return $array;
         
		          
		}
		catch(Exception $e)
		{
			die($e->getMessage());
		}
	}
  

}
   
?>

And I clarify that I also call sesion_start () in the template document .. what can it be?

Here is the javascript inside login:

var usuarios;
$(document).ready(function() {
    
    $("#guardar").click(function(){
        var usuario = $("#usuario").val();
        var pass = $("#pass").val();
        $.ajax({
	  
            type: "POST",
            url: "../gestionweb/views/procesologin.php",
            data: { "accion": "ingresar","user":usuario,"pass":pass}, 
       dataType:'json',
            error: function(){
                alert("error petición ajax");
            },
            success: function(data){
               
        if(data.length===0){
            alert("login incorrecto");
        }else{
           
            window.location.href="index.php?controller=template&action=index";
        }
               
            }
        
    });

         
  

          
});

By clicking on save, send user and pass to php.

Thanks

The session arrives perfectly because I do a session var dump:

Bone error is in the same index: IF I put an index article to redirect it, it opens the catalog of products perfectly, but why does not it open the template of the page?

In addition, the call remains with state 302 in the browser response.

    
asked by Caruso 26.11.2018 в 14:11
source

0 answers