0
I logged in in PHP, where I validated the data via Ajax and I load a PHP page into a DIV, so I don’t have to refresh the whole page. So far so good.
<?php
if(!isset($_SESSION)){
session_start();
}
$username = $_POST['name'];
$password = $_POST['pwd'];
$username_esc = addslashes($username);
$password_esc = addslashes($password);
include("conexao.php");
mysql_select_db("mg", $conn) or print(mysql_error());
$query = "SELECT id_usuario, nm_login, nm_senha, nm_nome, nm_sobrenome, nm_imagem FROM tbl_usuario WHERE nm_login='".$username_esc."' AND nm_senha='".$password_esc."'";
$result = mysql_query($query,$conn) or die(mysql_error());
$num_row = mysql_num_rows($result);
$row=mysql_fetch_array($result);
if( $num_row >=1 ) {
echo 'true';
$_SESSION['usuario']=$row['id_usuario'];
$_SESSION['login']=$row['nm_login'];
$_SESSION['nome']=$row['nm_nome'];
$_SESSION['sobrenome']=$row['nm_sobrenome'];
$_SESSION['avatar']=$row['nm_imagem'];
}
else{
echo 'false';
}
?>
-
$(document).on('click', '#login', function () {
username=$("#username").val();
if (username == "") {
$("#add_erro_login").html("Digite o usuário cadastrado");
$("#username").focus();
return false;
}
password=$("#password").val();
if (password == "") {
$("#add_erro_login").html("Digite a senha cadastrada");
$("#password").focus();
return false;
}
$.ajax({
type: "POST",
url: "login.php",
data: "name="+username+"&pwd="+password,
success: function(html)
{
if(html=='true')
{
document.form1.loading.style.visibility = "hidden";
$("#login-form").fadeOut("slow");
$("#background-on-popup").fadeOut("slow");
$("#perfil").fadeOut("fast");
$("#perfil").load("perfil.php");
$("#perfil").fadeIn("fast");
}
else
{
document.form1.loading.style.visibility = "hidden";
$("#add_erro_login").html("Usuário ou Senha inválido");
}
},
beforeSend:function()
{
document.form1.loading.style.visibility = "visible";
$("#add_erro_login").html("");
}
});
return false;
});
The problem is time to recover the $_SESSION['user'] at the top of the site. Because when it is loaded it is empty, since the user is not logged in, and then as I update only the DIV, it remains empty.
It would have as recovers this variable without having to refresh the whole page?
Did you ever solve your previous question? http://answall.com/questions/38590/vari%C3%A1vel-Session-do-php-empty
– brasofilo
No, that’s why I tried to explain it better
– Ricardo
Is that if the problem is the same, you should improve that question, and not open a new...
– brasofilo