从以前的位置恢复 webapp? [英] resume webapp from previous position?

查看:19
本文介绍了从以前的位置恢复 webapp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 web 应用程序,它会随着用户的进展存储用户数据,以便他们在 iPhone 上的主屏幕应用程序模式下单击外部链接并离开应用程序查看网页或类似内容时.

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.

当他们返回 webapp 时,如何在同一位置恢复.?目前它不会去相同的位置,它重定向到主页我想要从以前的位置恢复..

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..

知道怎么做吗?

推荐答案

Web 应用程序(在大多数情况下)不可能从它停止的地方恢复,因为因为用户正在存储 Web 应用程序图标(假设在iOS 设备)作为其主屏幕上的书签,当他们返回到网络应用程序时,它只会启动该特定网页作为网络应用程序.

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.

但是,您可以做的是设置一个 cookie(通过 PHP 或 Javascript)等于用户每次查看移动应用中的页面时查看的完整 URL.例如(在 PHP 中):

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, '/');

答案:

在您的主页上,在显示任何内容之前,请检查 PHP(或选择的语言)是否设置了 $_COOKIE['lastPage'].如果是,则执行 if 语句将用户重定向到上次查看的页面.

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();
    } 
?>

这对用户来说将是无缝的,并且看起来好像网络应用程序正在记住"他们的会话.因此,在除主页之外的每个页面的顶部,您可以在显示任何内容之前放置以下代码(将 pageUrl 中的 URL 替换为每个单独页面的实际 URL):

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, '/');
?>

遍历数据库结果:

<?php     
    foreach(database['row'] as $variableName => $variableValue) {
        setcookie($variableName, $variableValue, time()+86400, '/');
    }
?>

这篇关于从以前的位置恢复 webapp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆