Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

resume webapp from previous position?

I have a webapp which stores the users data as they progress so that if they click on an external link while in the home screen app mode on an iPhone and leave the app to view a webpage or similar.

When they return the webapp how will resume at the same position.? currently its not going to same position, its redirecting to home page i want its resume from previous position..

How to do this, any idea?

like image 326
mans Avatar asked Oct 10 '12 09:10

mans


1 Answers

It's not (for the most part) possible for a web app to resume where it left off, because since the user is storing the web app icon (assuming on an iOS device) as what is essentially a bookmark on their homescreen, it just launches that specific web page as the web app when they go back into the web app.

What you COULD do however, is set a cookie (via PHP or Javascript) equal to the full URL that the user is viewing every time the user views a page in the mobile app. For example (in PHP):

//--- Set lastPage cookie for 24 hrs for your domain --- //
setcookie('lastPage', 'http://www.example.com/products/bicycles', time()+86400, '/');

ANSWER:

On your homepage, before displaying any content, check with PHP (or language of choice) if $_COOKIE['lastPage'] is set. If it is, perform an if statement redirecting the user to that last viewed page.

<?php
    if(isset($_COOKIE['lastPage'])) {
        header('location: '.$_COOKIE['lastPage']);
        exit();
    } 
?>

This will appear seamless to the user, and will make it appear as if the web app is "remembering" their session. So at the top of every page other than the homepage, you would place the code below before any content is displayed (replacing the URL in pageUrl for the actual URL of each individual page):

<?php     
    $pageUrl = 'http://www.example.com/products/bicycles/';
    setcookie('lastPage', $pageUrl, time()+86400, '/');
?>

To loop through database results:

<?php     
    foreach(database['row'] as $variableName => $variableValue) {
        setcookie($variableName, $variableValue, time()+86400, '/');
    }
?>
like image 78
adamdehaven Avatar answered Sep 19 '22 02:09

adamdehaven