4
I have a system from which I use session to validate the user. For validation I use the code below:
<?php
session_start();
public function validaUsuarios($loginUsuario,$senhaUsuario){
.......
$_SESSION['logado'] = true;
header('location: entrar.php');
......
?>
And on the page enter.php:
<?php
session_start();
if($_SESSION['logado'] == false || $_SESSION['logado'] == ''){
header('location: index.php');
}else{
...........
What I do not understand is that in other servers worked perfectly, but this server does not take first, IE, when giving a print, does not pass any value in the session.
The function
validaUsuarios
is within a class?– Oeslei
Yes. It is inside a class and at the top I put session_start(). <? php session_start(); class Extends Methods Connect{
– user24136
what I find strange is that it returns to the login page and when soon me again, he "sees" the value and I can access.
– user24136
Try to put
exit();
below redirects. For example:header('location: entrar.php'); exit();
– Oeslei
I put it, but it didn’t work. The session still doesn’t get the value right the first time, only the second time....
– user24136
Try to see the contents of
$_SESSION
right after the line$_SESSION['logado'] = true;
to see if you are in session. ex.:var_dump($_SESSION);die;
Maybe the problem isn’t in the piece of code you posted.– Kallef
I did it the way you asked and it appears the values, IE, the value is created, but when it arrives in the other page, the value arrive empty.
– user24136
I would say it has something to do with Handler’s mistakes. Try changing the
if($_SESSION['logado'] == false || $_SESSION['logado'] == ''){
forif(isset($_SESSION['logado']) === false){
because in fact, at the first moment there is no index 'logged in' and your server may be returning a Warning and not false or empty.– Gê Bender
Hi, Gê. The problem is that in the address page there is no value in $_SESSION['logged in], that is, when I do the validation the value appears as 1, but when it arrives in the page that is directed, the value arrives empty.
– user24136
Create a phpinfo.php file, put the <?php phpinfo(); ? > save the return and put it somewhere so we can analyze.
– Hiago Souza
If possible send from a working server and one that doesn’t work, it may be some configuration on the server.
– Hiago Souza