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

478

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.

853

Answer

Solution:

Not 100% sure what you trying to do, but to persist some info like a session you would be better off using Ti.Properties or localStore of the SQLite DB.

200

Answer

Solution:

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.

People are also looking for solutions to the problem: php - updateAll with relationships in CakePHP 2

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.