How to store and rescue Session value through jquery?

Asked

Viewed 936 times

1

I am developing a mobile application with intel XDK I have to do a login which will be validated by the php file that contains all validations and ultimately stores in session the values I need user do not know and how can I redeem these values to list on the next page when the login was successfully carried out. if possible, I would like to know the best solution and a basis for how it can be done.

  • Do with AJAX, return make your file php return the data from user who are in session, make an ajax request and receive this return.

  • Yes but this session as it will be stored and on the mobile I still do not understand very well

  • Your file PHP you will normally do the session control, the ajax makes identical requisitions to those of a form, but no need to reload the page.

  • and make another PHP file with user data and return a json with the data to show right ?

  • Is one of the solutions.

  • But I can get it from the same file where I declare Session if yes I could answer a simple example of how it would look

  • Observe the answer and see if it meets your need

Show 2 more comments

1 answer

2

Php

// Antes faça toda a declaraçao da sessão
function getUserSession(){
    return json_encode($_SESSION["user"]);
}

// Verifica se o login foi executado
if($login){
    getUserSession();
}

Javascript

$.post( "arquivo.php", { user: "John", password: "*****" }, function( data ) {
  console.log(data); // Retorna os dados da sessão do usuário logado, ou da falha na autenticação em formato jSon
}, "json");
  • Could you elaborate on your answer? She’s too shallow...

  • @Felipeavelar Flat House, kkkkkkk, blz I’ll put an example of ajax too soon

  • 1

    @Felipeavelar ready, a practical example of how to perform the action

Browser other questions tagged

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