How do I apply this Login class to my Login form?

Asked

Viewed 32 times

0

     <?php 
        if (!empty($_POST)) {
            // Recebendo dados do Formulário
            $usuario = $Modulo->NoSqlInject((isset($_POST['usuario'])) ? $_POST['usuario'] : NULL);
            $senha   = $Modulo->NoSqlInject((isset($_POST['senha'])) ? $_POST['senha'] : NULL);
            // Iniciando o processo de conexão 
            $Usuario->LogarUsuario($usuario, $senha, '/index.php');
        }
    ?>
    <div class="login-box-body">
        <p class="login-box-msg">Faça login para iniciar sua sessão!</p>
        <form method="POST">
            <div class="input-group has-feedback">
                <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
                <input type="text" class="form-control" name="usuario" placeholder="Digite o nome de usuário" required>
            </div>

            <div class="input-group has-feedback" style="margin-top: 3%;">
                <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
                <input type="password" class="form-control" name="senha" placeholder="Digite a senha do usuário" required>
            </div>

            <div class="row" style="margin-top: 3%;">
                <div class="col-xs-8">
                    <div class="checkbox icheck">
                        <label><input type="checkbox" name="rememberme" value="rememberme"> Lembrar-me</label>
                    </div>
                </div>

                <div class="col-xs-4">
                    <input type="submit" class="btn btn-primary btn-block btn-flat" value="Acessar"></input>
                </div>
            </div>
        </form>
    </div>

above is my form, but so far so good, works normal.

The $Usuario->LogarUsuario($usuario, $senha, '/index.php'); it does its verification process and creates the $_SESSION normal, but this is where I need help, I want to put these $_SESSION to work outside, below is my User.class.php

Usuario.class.php Well, if there is any error help me, and I need to put the "Remember My Password" also outside, it’s all there the script.

  • What do you mean out? To access the session variables it is always necessary to start a session_start(); so I saw in your code only the method login user starts the session. After the page is reloaded it is necessary that the recurring script has started a session as well. But still I can’t understand where you want to use the variables where in which script?

  • Ready Atila Silva, I put a session_start(); outside the . class, is that I want to make the script like this: if($_SESSION['usuario_logado'] == TRUE) { echo 'SUCCESS! '; } Else { echo 'FAILED'; } ie == FALSE, get it? only this I have to put out of .class.php in my HTML file! That’s what I’m not getting, I can create the session by logging in, except make it run outside the class!

  • I got it, man! https://answall.com/questions/286406/como-rodar-um-update-constante-no-session. if you can help me with that, thank you!

  • Well. Object orientation can solve the problem. I’m not that good a code reader. However, it is always good to remember that object orientation moves to decrease the repetitive use of code. Well you could follow the recommendations so your code becomes easier to understand and implement. https://answall.com/a/55508/74982

No answers

Browser other questions tagged

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