Display user info upon logging in using php session (Hybrid App)

£可爱£侵袭症+ 提交于 2019-12-23 04:45:30

问题


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.

来源:https://stackoverflow.com/questions/37669015/display-user-info-upon-logging-in-using-php-session-hybrid-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!