简体   繁体   中英

TideSDK Desktop: How to create a login system with PHP session?

I want to create a login system in my desktop application using TideSDK. I have tried to use PHP session, but when I run the application and click some link to another page, the session I have set is disappeared. However, if I run on Web Browser, it works correctly.

I have tried to search, but I cannot find some question that involve with my questions.

I would like to know how to deal with PHP session in TideSDK Desktop or is there an alternative to create the authentication system ?

Thank you for your help.

不能100%地确定要做什么,但是要保留某些信息(例如会话),最好使用Ti.Properties或SQLite DB的localStore。

The way I solved the problem looks like this:

on the PHP side:

public function login($email_address, $password) {
    $email_address = filter_var($email_address, FILTER_VALIDATE_EMAIL);
    $password = filter_var($password, FILTER_SANITIZE_STRING);

    if (is_valid_login($email_address, $password)) {
        return json_encode( array('status' => 'Logged in', 'session_id' => session_id()) );
    } 
    return json_encode( array('status' => 'Failed login') );
}

on the TideSDK side:

$.ajax({
    type: "POST",
    url: login_url,
    data: {
        'email_address' : email_address,
        'password'      : password
    },
    success: function(data, status, xhr) {
        if (data.status == 'Logged in') {
            Ti.App.Properties.setString('loggedIn', 'true');
            Ti.App.Properties.setString('sessionId', data.session_id);
        } else {
            Ti.App.Properties.setString('loggedIn', 'false');
        }
    }
});

Then each connection back to the server is initialized like this:

var httpClient = Ti.Network.createHTTPClient();
httpClient.setCookie('PHPSESSID', Ti.App.Properties.getString('sessionId'));

And then it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM