Login to the user’s account inside the Index page

Asked

Viewed 138 times

-2

I’m developing a system where all employees can enter the Index.php page (Work page), in general where they all know the code and password and enter the system normally (No restrictions and in this case for those who get to work first:)), only when one enters shows all employees.

So I want when one of them wants to change their data, or see your page, it is directed on your page and when leaving back to the index.php page that was already logged in without having to log out of it and then log in 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?

  • 1

    The question is a little confusing. Portanto eu quero quando um deles quiser alterar os seu dados ou ver a sua página ela é direcionada na sua página e ao sair, volta para a página index.php que já estava logado sem ter que sair dela e depois logar novamente. This one is probably the first to come to work and log in, right? Explain this better sem ter que sair dela, open his page in the same window?

  • Sorry about the mess. What I mean is: We have the main page where all employees have access (the password) and on this page is listed all employees. However, when an employee wants to access your page, clicking the k button opens a modal where he will put his password when clicking the "log in" button must redirect to his page. Now when he wants to leave his page go back to the main page where everyone has access without having to log in again. IN OTHER WORDS: The page of the employee must be inside the main page p/ when leaving pemanencer on the main page.

  • You could open the employee page in a new tab or window, so the main page would be open in the other tab. Now, A pág do funcionário deve estar dentro da pág principalis smelling me be a modal in which he can see and edit his data.

  • Then it can be as follows: When you click the button opens the modal, puts the password and opens a new tab in the employee account

  • If the answers to your questions solve the problem, mark them as accepted. See how and why in https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079

  • I saw in a question of yours, in the reply comment Foi resolvido sim! Valdeir Psr, muito obrigado. Mas nao tenho ideia onde marcar que esta resolvido, tem algum sitio para marcar caso tenha resolvido aqui no StackOverflow . To mark an answer as accepted, click the check mark on the left side of the answer; its color will change from gray to green. See https://i.stack.Imgur.com/vhKaX.png

Show 1 more comment

1 answer

1


Edited 12/04/2018 10:36

Second comment from AP

Then it can be as follows: When you click the button opens the modal, puts the password and opens a new tab in the employee account

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

Working example

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>
<script src="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>

php user.

<?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); 
?>
  • Thank you very much Leonardo for the willingness and patience. I used your code with some bad changes everything is working well. I thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.