Display username after logging in

Asked

Viewed 749 times

-1

So after long hours trying to display the login user name only I could not.

I think something is wrong just don’t know where it’s wrong xD

PHP:

<?php 
    require('config.php'); //INICIA A CONFIG PHP
    config_start(); 
    ?>

  <?php
    $email = $_POST['email'];
    $senha = $_POST['senha'];

    $query = @mysql_num_rows(mysql_query("SELECT * FROM cadastro WHERE email='$email' AND senha='$senha'"));
            if($query == 1){
            echo'<div style="background: rgb(36, 182, 36) none repeat scroll 0% 0%; color: white; padding: 4px; font-weight: bold;">Logado com Sucesso.</div>';
            echo "<script>setTimeout(window.location.href='http://pentazynetwork.pe.hu/biblioteca/plugins.php', 2);</script>";
            echo "<script>window.location.assign('".PATH."')</script>";
            echo "<script>document.getElementById('usuario_login_form').style.border='1px solid green'</script>";
            echo "<script>document.getElementById('senha_login_form').style.border='1px solid green'</script>";
                    $user_ip = $_SERVER['REMOTE_ADDR']; //Pega o IP do usuário
                    date_default_timezone_set('America/Sao_Paulo');
                    $last_login = date("d/m/Y | H:i:s");

                    mysql_query("UPDATE cadastro SET user_ip='$user_ip', last_login='$last_login' WHERE email='$email'");
                    $_SESSION['usuario'] = $email; // INICIA A SESSÃO
                    $_SESSION['senha'] = $senha; // INICIA A SESSÃO
                }else{
                    echo '<h5>USUARIO OU SENHA INVALIDOS!</h5>';
                    echo "<script>setTimeout(window.location.href='http://pentazynetwork.pe.hu/biblioteca/login.php', 2);</script>";
                }
    ?>

INDEX:

  • you want to display the name or the email? looking at your code it will only show the email. ps: it is not a good practice to save the user password in session.

  • enter the session_start() line before into php

1 answer

1

In your php, first of all, put the line

session_start();

Example:

<?php 
    session_start(); 
    require('config.php'); //INICIA A CONFIG PHP
    config_start(); 
?>

And on your index too

<?php 
 session_start();
 ?>
<center>
  <br>
  <button class="w3-btn w3-green">20 novos plugins serão adicionados! Saiba mais.
    <?php echo $_SESSION['usuario']; ?>
  </button>
</center>

I hope I’ve helped.

Browser other questions tagged

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