Pass variable hidden in php page redirect

2

I've been doing a job and I need to finish php redirecting pro index along with a variable at the end of my login login. In the login I made a select where I returned the nickname of the user, now I need to send that nickname to the index in order to make other queries there from this nick. how can I do this without being exposed in the url or source code?.

I'm new to the web, I do not know how to do it.

I had made this code:

if(isset($_POST['submeter'])){
        $email = $_POST['email'];
        $pass = $_POST['senha'];
        $pass = hash('sha256', $pass);
        $stmt = $connect->prepare("SELECT loginUsuario FROM usuario WHERE email =? and senhaUsuario=?");
        $stmt->bind_param('ss',$email,$pass);
        $stmt->execute();
        $stmt->store_result();
        if($stmt->num_rows <=0){
            echo "<h3 id='erro'>E-mail ou senha incorretos!</h3>";
        }else{
            $result= $stmt->bind_result($loginUsuario);
            $stmt->fetch(); 
            setcookie("login",$email);
            header("location: index.php"); //passar $loginUsuario junto de alguma forma.
        }
    }
    
asked by anonymous 11.11.2017 / 22:01

1 answer

1

You can also use session.

Note: session_start(); is required and should be the first element of your page, before any html entry

 <?php 
 session_start();
 ................
 ................
 if(isset($_POST['submeter'])){
    $email = $_POST['email'];
    $pass = $_POST['senha'];
    $pass = hash('sha256', $pass);
    $stmt = $connect->prepare("SELECT loginUsuario FROM usuario WHERE email =? and senhaUsuario=?");
    $stmt->bind_param('ss',$email,$pass);
    $stmt->execute();
    $stmt->store_result();
    if($stmt->num_rows <=0){
        echo "<h3 id='erro'>E-mail ou senha incorretos!</h3>";
    }else{
        $result= $stmt->bind_result($loginUsuario);
        $stmt->fetch(); 
        setcookie("login",$email);

        //criando a session
        $_SESSION["login"]=$email;            

        header("location: index.php"); //passar $loginUsuario junto de alguma forma.
    }
}

In index

<?php 
session_start();
$login=$_SESSION["login"];

//caso queira usar o cookie
//$login=$_COOKIE['login'];
    
11.11.2017 / 23:47