2
I was doing a job and I need to finish my login on the login page, php redirect pro index along with a variable. In the login I made a select where returned me the nickname of the user, now I need to send this 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 don’t know how to do this.
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.
}
}
You used a cookie
setcookie("login",$email);
to store this information is not better to retrieve the cookie? type$_COOKIE['login']
? I don’t know if it’s the best way, it was based on your code.– novic
This cookie command I saw on the internet, I don’t know how to use it. Can you explain to me what parameters I put in and where this cookie is "stored"? And how to retrieve it on the other page.
– Matheus Mendes
Cookie is on the client’s machine, in the browser and you can recover on the index page for example with the command
echo $_COOKIE['login'];
.– novic
you can also use Session.
– user60252
Can you give me an example of Session? I don’t know about security when using cookies.
– Matheus Mendes