ngplayground
ngplayground

Reputation: 21647

iPhone Home Screen Web App and Staying Logged In

I've been using PHP Session to stay logged in when I'm using a browser but when I save the web app to my Home Screen and launch the app, I have to Sign In each time I open up the app. Is there a way to stay signed in?

Could anyone supply an example of code or point me in the right direction as I looked into Local Storage and not sure how to set the LocalStorage value when I am Logged In and how to check the value exists.

NOTE: I currently use PHP to Sign In

Thanks

index.php

<script type="text/javascript">
    <?php echo $_SESSION['logged'];?> 
    <?php if ($_GET['logged'] == 1){?>
        $.cookie( 'loggedin', '1',  { expires: 7, path: '/' } );
    <?php }?>
        if( $.cookie('loggedin') == '1' ) { 
            <?php $userlog = true?>
            $.cookie( 'loggedin', '1',  { expires: 7, path: '/' } );
        } else {
            <?php $userlog = false?>
        $.cookie( 'loggedin', '0',  { expires: 7, path: '/' } );        
        }
</script>

$_SESSION['logged'] is set from the sign-in.php file

sign-in.php

    if($count==1) {
        session_register("username");
        $_SESSION['logged']= $user;
        header("location: /?logged=1");
    } else {
        echo "Your Login Name or Password is invalid";
    }

Upvotes: 2

Views: 1340

Answers (3)

ngplayground
ngplayground

Reputation: 21647

I currently use LocalStorage which works fine

Upvotes: 0

rptwsthi
rptwsthi

Reputation: 10172

I'm not sure what is problem but if sustainable local storage is what you want, to check if you were logged in, after you iOS APPLICATION get close then here it is:

set a flag to user default such as:

  [[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:@"isLogin"];

then retrieve this value when application launch to check if u were logged in:

 BOOL isLogin = [[NSUserDefaults standardUserDefaults] valueForKey:@"isLogin"];

Now perform what you need accordingly.

Upvotes: 0

Ariel
Ariel

Reputation: 26773

I'm pretty sure you don't need LocalStorage.

Just set a cookie with an expiration in the future, rather than a session cookie (which is deleted when the browser closes).

You probably can't use PHP sessions for this since those are regularly deleted. Instead you have to handle the login cookie yourself.

Upvotes: 1

Related Questions