How do I pull all user data from Session?

Asked

Viewed 86 times

0

To summarize, I created a page where the user when logging in will be able to see your data, it is responsible for displaying all of them and still some options to edit (but this is not what interests me now). What I really need to figure out is how to solve this problem:inserir a descrição da imagem aqui

Because it is the email that is what the user uses to log in appears, but the other data does not.

What I did was use a system to store the data in the file that receives the login data. IE, in the login validation file has this system to store data that is not needed at the time of logging in, but required on this page above.

Here is the validation code that I said has the SESSION storage:

?php 

session_start();
$email = $_POST["email"];
$senha = $_POST["senha"];
    
//adiciona barras para evitar SQL injection
$loginSeguro = addslashes($email);
$senhaSegura = addslashes($senha);
    
//testa para saber se os campos estão vazios
if (empty($email) or empty($senha)):
    echo "
          alert('Preencha todos os campos');
          history.go(-1);
          ";
exit;    

endif;

//inclui a conexao
include 'core/home/database.php';

//consulta ao banco de dados $dados = @mysqli_query($mysqli, "SELECT * FROM users WHERE email ='$loginSeguro' AND senha = '$senhaSegura'");

//armazena na variável o número de linhas encontradas $num = @mysqli_num_rows($dados);

//se zero, é porque ele errou a senha ou o login if ($num == 0): echo " alert('Usuario ou senha Incorreta'); history.go(-1); "; exit; else :

//armazena a função fetch_object onde é tratado como objeto
$linha = @mysqli_fetch_object($dados);

//armazena na variável o número ID do usuário 
$coduser = $linha->idUsuario;
    
//armazena na sessão o ID do usuário logado 
$_SESSION["id"] = $coduser;

//armazena na sessão o nome do login.
//aqui pode ser e-mail, login, nome do usuário e etc.
$_SESSION["email"] = $email;
$_SESSION["nome"] = $nome;
$_SESSION["sobrenome"] = $sobrenome;
$_SESSION["plan"] = $plan;
$_SESSION["image"] = $image;
$_SESSION["cardtype"] = $cardtype;
$_SESSION["cardate"] = $cardate;
$_SESSION["profile2"] = $profile2;
$_SESSION["profile3"] = $profile3;
$_SESSION["profile4"] = $profile4;

    
//manda o usuário para a páginas depois de logado       
header ("Location: home");

endif;

?

OK this script up there is the validation page that takes the person home, and yes this script is working he logs in and n lets the person access through the URL bar, well he and this one:

?php
session_start();
setcookie("ck_authorized", "true", 0, "/");

/*testa se a sessão tem valor.
  Refere-se a linha lá no arquivo de login onde
  é inserido o login na sessão. */
if(!isset($_SESSION["email"])){
     header("location: /");
}else{
$email = $_SESSION["email"];
}

  
?

This is called login validation, it’s on every page I want to leave private. Note:I Linkei him using the metedo include.

And this one is the menu script, which tmb is included on all pages using the same checker method. This menu contains this line

<a name="dropem" href="/account ?php echo $_SESSION["id"];? " style="left: -123px;"> ?php echo $_SESSION["email"];  ?> label id="icone"> /a>
that leads to the page Account. What is this here, that is what is causing me headache:



    

    
  
 


  none
     Detalhes da sua conta Watch+

   
  Nome
   

Alterar Nome none "> Foto de Perfil none E-mail |
<form class="line2"><h5 style="visibility: hidden;">none</h5></form>
<strong style="color: grey;">Plano Selecionado</strong>
<h4><i class="fa fa-box"></i> | <?php echo $_SESSION['plan']; ?></h4>

<form class="line2"><h5 style="visibility: hidden;">none</h5></form>
<strong style="color: grey;">Tipo do Cartão</strong>
<h4><i class="fa fa-credit-card"></i> | <?php echo $_SESSION['cardtype']; ?></h4>

<form class="line2"><h5 style="visibility: hidden;">none</h5></form>
<strong style="color: grey;">Data de Vencimento do Cartão</strong>
<h4><i class="fa fa-calendar-alt"></i> |  <?php echo  $_SESSION['cardate']; ?></h4>

<form class="line2"><h5 style="visibility: hidden;">none</h5></form>
<strong style="color: grey;">Perfis que também usam essa conta</strong>
<h4><i class="fa fa-users"></i> | <?php echo  $_SESSION['profile2']; ?>, <?php echo  $_SESSION['profile3']; ?>, <?php echo  $_SESSION['profile4']; ?></h4>
<form class="line2"><h5 style="visibility: hidden;">none</h5></form>
<h4><i class="fa fa-angle-double-down"> | </i> Outras Opções</h4>
Encerrar minha conta

Someone knows how to fix these codes, as the pre of the site is not completing everything and leaving perforated. So some things in the codes are without the "<" php, but n know, if someone can fix ai pq if not. Can’t understand the code

2 answers

1


See if this Account page has "start_session()" at the beginning and see if it also has the "<? php" tag. Test it first, and put it here as it stood.

And to see the data stored in SESSION, just take a var_dump($_SESSION). Like this:

    session_start();
var_dump($_SESSION);
  • hello friend, I managed to solve the problem, I studied the code and fixed the errors. But still, thank you very much.

0

in page Account has session_start() at the beginning?

  • if not right use this ini_set('display_errors',1); ini_set('display_startup_erros',1); error_reporting(E_ALL);

*** will show source code errors.

  • yes, I put a Session. I put on the menu page that is included in this from Account. and also in all the others that use the login system as security, I put once in Account, and I took from the menu, but then the error continues so did not help much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.