Login to the user account in the index page [closed]

-2

I'm developing a system where all employees can enter the Index.php page, generally where they all know the code and password and normally enter the system (No restrictions and in this case for whom get first at work :)), only what when one enters shows all employees.

So I want it when one of them wants to change their data, or see your page, it is directed on your page and when you exit back to the page index.php that was already logged in without having to leave it and then log again.

For this I wanted to ask only the employee password through the modal window to be redirected to his page. Can someone help me with this please?

    
asked by anonymous 11.04.2018 / 13:54

1 answer

1
  

Released 04/04/2018 10:36

Second AP Review

Then it can be as follows: When you click the button open the modal, enter the password and open a new tab in the official account

  

If that's what you want, then post the code explanation.

Example running

Page index

<?php
session_start();

$connect = new mysqli ("localhost", "USUARIO", "SENHA", "NOME_DB");

$textoLabel="Digite sua senha";

if (isset($_POST["senha"]) && $_POST["senha"]!="") { 
    $senha = $_POST["senha"];
    $id = $_POST["campoOculto"];

    $sql="select * from nomeTabela where senha='$senha' && id='$id'";

    $buscar=mysqli_query($connect,$sql);
    $result=mysqli_num_rows($buscar);

    if ($result==1) {
        $dados=mysqli_fetch_array($buscar);
        $_SESSION["usuario"]=$dados["nome"];
        echo '<script>window.open("usuarios/usuario.php");</script>'; 
    }else{
        $textoLabel = "Senha inválida";
        $modal="mostrar";
    }

}
if (isset($_POST["senha"]) && $_POST["senha"]=="") {
    $textoLabel = "Você deve digitar sua senha";
    $modal="mostrar";
}

?>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<script>
function setaDadosModal(valor) {
    document.getElementById('campoOculto').value = valor;
}
</script>

<?php
if ($modal=="mostrar"){
?>
<script>
    $(document).ready(function () {
    $('#myModal').modal('show');
    });
</script>

<?php
}

    $sql2="select * from nomeTabela";
    $listar=mysqli_query($connect,$sql2);

    $tabela .= '<div style="float: center" table align="center">';

    $tabela .= '<table border="1">';

    $tabela .= '<tr>';

    $tabela .='<thead>';

    $tabela .= '<tr>';

    $tabela .= '<th>nome</th>';

    $tabela .='</thead>'; 

    $tabela .='<tbody>';

    while($rows = mysqli_fetch_assoc($listar)) {

        $tabela .= '<tr>';

        $tabela .= '<td><a data-toggle="modal" data-target="#myModal" class="btn btn-primary" onclick="setaDadosModal(\''.$rows['id'].'\')">'.$rows['nome'].'</a></td>';

        //$tabela .= '<td><button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal" onclick="setaDadosModal(\''.$rows['id'].'\')">'.$rows['nome'].'</button></td>';

    }

    $tabela .= '</tr>';

    $tabela .='</tbody>'; 

    $tabela .= '</table>';

    $tabela .= '</div>';

    echo $tabela;

    mysqli_close($connect); 
?>


<div id="myModal" class="modal fade">
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <h4 class="modal-title">Login </h4>
        </div>
        <form id="mudarsenha" method="post" name="form_mudar_senha" action="" autocomplete="off">
        <div class="modal-body">
            <div class="md-form ml-0 mr-0">
                <input name="senha" type="password">
                <input type="hidden" name="campoOculto" id="campoOculto">
                <label data-error="wrong" data-success="right" class="ml-0"><?php echo $textoLabel ?></label>
            </div>
        </div>
        <div class="modal-footer">
            <button type="submit" class="btn btn-success btn-rounded waves-effect waves-light" ><span class="btn-label"><i class="fa fa-send"></i></span> Enviar</button>
            <button type="button" class="btn btn-success waves-effect waves-light" data-dismiss="modal">Close</button>
        </div>
        </form>
    </div>

   

user.php

<?php
session_start();

$connect = new mysqli ("localhost", "USUARIO", "SENHA", "NOME_DB");

echo "Pagina do usuario ".$_SESSION["usuario"];

$nome = $_SESSION["usuario"];

$sql="select * from nomeTabela where nome='$nome'";

    $listar=mysqli_query($connect,$sql);

    while($rows = mysqli_fetch_assoc($listar)) {

      ........
      ........

    }

    mysqli_close($connect); 
?>
    
12.04.2018 / 04:08