Display user info upon logging in using php sessio

2019-06-10 20:21发布

问题:

Developing Hybrid App I know it is possible to use php session. Anyone know how it works? I would like to display all the info of the user logged-in on their home page like, fullname, contact no., address, etc.

The login: (login.html) This is the code with ajax:

function handleData(responseData) {
                var response = JSON.parse(responseData);
                var access = response.user_access;

                if (access == "real") {
                    alert("Welcome");
                    location.href = "home.html";  //should redirect and auto display all the info. 

                } else {
                    alert("Your username and password didn\'t match.");

                }
            }

So the login page send request to the server to log-in.

Now the server side(PHP) code.

if(isset($_POST['input_email']) && isset($_POST['input_password'])){

            $post = $_POST;
            array_walk_recursive($post, 'clean');

        //SQL query here- check if email/password match
        $using = 'real';
}

if($user['user_status'] == 'active'){
                $_SESSION['user_id'] = $user['user_id'];
                $_SESSION['user_email'] = $user['user_email'];
                $_SESSION['user_fullname'] = $user['user_fullname'];
}else{
        $using = 'notmatch';
}

Declare variable for session:

$user_fullname = $_SESSION['user_fullname'];
$user_id = $_SESSION['user_id'];
$user_email = $_SESSION['user_email'];

$result_array = array( user_id => $user_id, user_fullname => $user_fullname, user_email => $user_email, user_access => $loggedinusing);

echo json_encode($result_array);

}

Login was working well and redirected to the home page when login credentials are right. My home.html for now don't have any code. I need for now is to display the user info in home page with PHP session. I don't know where to start.