1
I have a problem that’s never happened to me before. My balance session variable does not update on the .php. page.It is updated in the database after an UPDATE. But on the page is only updated if I log out and log back in. What will be the problem?
These are my session pages
//init.php
<?php
session_start();
mysql_connect('localhost','root','usbw');
mysql_select_db('cern_cn');
date_default_timezone_set('Europe/Lisbon');
?>
//login.php
<?php
include ('init.php');
include ('con_cern_db.php');
session_regenerate_id();
//CONSULTA DO UTILIZADOR
$consulta="Select * from login where username='" . $_POST['username'] . "' and password='" . $_POST['password'] . "' AND saldo AND id";
$resultado=mysql_query($consulta);
if (mysql_num_rows($resultado)>0) //SE O EMAIL E A PASSWORD COINCIDIREM
{
//COLOCA NA VARIAVEL LINHA OS DADOS DA CONSULTA
$linha=mysql_fetch_array($resultado);
//COLOCA O EMAIL EM SESSAO
$_SESSION['username']=$linha['username'];
$username=$_SESSION['username'];
$_SESSION['modo']=$linha['modo'];
$_SESSION['saldo']=$linha['saldo'];
$saldo=$_SESSION['saldo'];
$_SESSION['id']=$linha['id'];
$id=$_SESSION['id'];
//REDIRECCIONA A PAGINA PARA A PAGINA SECRETA
header("location: index.php");
}
else //CASO NAO COINCIDAM
{
//REDIRECCIONA PARA A PAGINA INICIAL REPORTANDO O ERRO
header("location: index.php?erro=1");
}
?>
That’s what I call her
<?php
if (isset($_SESSION['username'])) //SE EXISTIR AUTENTICAÇÃO
{
echo ' Olá ' . $_SESSION['username'] . '.<br/>';
echo ' ' . $_SESSION['saldo'] . '.Créditos<br/>';
//echo ' Modo ' . $_SESSION['modo'] . '.<br/>';
echo " ";
//--------------------------//
//TODO O CODIGO PRIVADO AQUI//
//--------------------------//
}
else //CASO NÃO ESTEJA AUTENTICADO
{
echo 'Esta é uma àrea reservada, só utilizadores podem ter acesso.';
}
?>
//logout.php
<?php
include ('init.php');
session_destroy();
header("location: index.php");
?>
You should probably be having the same session print out the id and see if it’s changing when you log out after login. When I am with this "freezing" of Session_regenerate_id I use the login page so it always forces to generate a new id for the session. Another qnd you logout the ideal tbm and clear the session with unset or Destroy.
– Thalles Daniel
Friend @Thallesdaniel, thank you for the reply. I really noticed that the session id after logout was always the same. Now I use session_regenerate_id(); . The problem continues. The field is updated in the database and my balance Session does not update. My logout has session_destroy();. What might be?
– David Concha
in the restricted page do so: $_SESSION['balance']='test changing balance'; E then print_r($_SESSION); and see if it changed. The problem may be depending on before Session of an echo in your select to see if exactly what’s going on.
– Thalles Daniel
when you are inside the protected page change the Session with other values and an F5 to see if you are changing
– Thalles Daniel
@Thallesdaniel the problem continues. I changed the balance to 10. then I upgraded to 15, I did not. Just logging out and logging in it updates
– David Concha
ta doing local?
– Thalles Daniel
yes, I am with Usbwebserver http://localhost:81/
– David Concha
can be tested on the web
– Thalles Daniel
you already gave a var_dump or a print on your query to see if it’s coming right?
– Thalles Daniel
I will test location on another computer and on the web tomorrow. the problem can only be local. If in the meantime you get another solution says.
– David Concha
had a problem with Session local tbm so I asked. Try restarting the server service.
– Thalles Daniel
You can create a function that searches in the database if the balance is the same as it is set in Session, if it is, leave it as true, if not, you put $_SESSION[balance] = $Row['balance'] updating to Session.
– Sr. André Baill
@Thallesdaniel tested with another local server, easyPHP, and the problem is the same
– David Concha
I don’t get it worked or n?
– Thalles Daniel
no, the problem remains the same
– David Concha
There is something wrong with your 1.verique $line['balance'] application before assigning it in the session. 2.destroy Session with Session array() Stroy and unset and remember to always do this by placing Session start at the top of the page. Test the web for the result because I did a test on mine yesterday and changed the time. Every page that uses Session needs to start with Session start and not seen on your login screen. And on the logout page the correct I know is so Session start and then Session Destroy believe that why it is not destroying.
– Thalles Daniel
A doubt, why are you using
session_regenerate_id
?– Guilherme Nascimento
has several reasons, duplicate Session, problems to change the Session, generate a new etc. http://php.net/manual/en/function.session-regenerate-id.php
– Thalles Daniel