Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
2.5 kB
2
Indexable
Never
<?php

include "../../conexion.php";


//Declaramos variables para insertar.
$username = $_POST['UserName'];
$userpass = $_POST['UserPass'];

//Llamamos el procedure
$stmt = "{ CALL spu_Login_User ( ?, ?, ?)}";
$res = 0;

//declaramos el array con los parametros
$params = array(

    array($username, SQLSRV_PARAM_IN),
    array($userpass, SQLSRV_PARAM_IN),
    array(&$res, SQLSRV_PARAM_OUT)

);

$result = sqlsrv_query($conn, $stmt, $params);



if ($result === false) {
    echo "Error in executing statement.\n";
    die(print_r(sqlsrv_errors(), true));
} else {

    if ($res == 0) {

        echo "error";
    } else {

        echo "success";

        //consultamos a la bd para obtener informacion del usuario que inicio sesion para luego guardarlo en una variable SESSION
        //CREAMOS LA CONSULTA
        $sql = "SELECT VU.UserID,VU.AccessID,VU.UserName,VU.WindowUser,VU.AccessName,VU.AccessLevel,VU.PassEnableChange,CU.TemplateID FROM [INV_VIE].[UserAccess] AS VU 
        JOIN INV_CFG.UserAccess AS CU
        ON VU.UserID = CU.UserID
        WHERE VU.WindowUser = '$username'";
       // echo $sql;
        //HACEMOS LA CONEXION CON LA CONSULTA
        $getResult = sqlsrv_query($conn, $sql);

        //Creamos las variables que queremos almacenar.
        $UserID;
        $AccessID;
        $UserName;
        $WindowUser;
        $AccessName;
        $AccessLevel;
        $PassEnableChange;
        $TemplateID;

        //AHORA LEEMOS CADA REGISTRO QUE NOS TRAE NUESTRA CONSULTA A LA BASE DE DATOS
        while ($row = sqlsrv_fetch_array($getResult, SQLSRV_FETCH_ASSOC)) {

            //creamos variables
            $UserID = $row['UserID'];
            $AccessID =  $row['AccessID'];
            $UserName = $row['UserName'];
            $WindowUser =  $row['WindowUser'];
            $AccessName =  $row['AccessName'];
            $AccessLevel =  $row['AccessLevel'];
            $PassEnableChange =  $row['PassEnableChange'];
            $TemplateID =  $row['TemplateID'];
            
        }

        //inicializamos la SESSION del usuario
        session_start();

        
        $_SESSION['usersession'] = array();
        $_SESSION['usersession']['UserID'] = $UserID;
        $_SESSION['usersession']['AccessID'] = $AccessID;
        $_SESSION['usersession']['WindowUser'] = $WindowUser;
        $_SESSION['usersession']['AccessName'] = $AccessName;
        $_SESSION['usersession']['TemplateID'] = $TemplateID;


    }
}


sqlsrv_free_stmt($result);
sqlsrv_close($conn);
Leave a Comment