【问题标题】:How to override php session expire on Android webview如何在Android webview上覆盖php会话过期
【发布时间】:2017-05-07 07:36:14
【问题描述】:

我是 Android 开发的新手。目前我正在开发 webview 应用程序。

webview(网站)有一个会话超时,例如 10 分钟。当会话过期时,它将重定向到登录页面。如果 android 处理/覆盖会话,这可能吗?我不希望会话在应用程序上运行时过期。

目前我已经尝试过使用 CookieManager,但它似乎不起作用。

【问题讨论】:

    标签: android webview


    【解决方案1】:

    我目前正在做的是: 让您的 android 应用通过 post 发送唯一的设备 ID

    String deviceId = Settings.Secure.getString(MainActivity.this.getContentResolver(),
                    Settings.Secure.ANDROID_ID);
    
            try {
                postData = "deviceId=" + URLEncoder.encode(deviceId, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            mainWebView.postUrl(postUrl,postData.getBytes());
    

    然后我做的是在主页(在android应用程序中启动)我检查android id是否在数据库中并且属于特定用户。

    //This is just pseudo code actual implementation depends your database and user login setup
    if(!isset($_POST["deviceId"]){
        //no deviceId sent
        //so redirect to login page
    }
    //check database for deviceId and see if it has a user id associated with  it
    if(deviceId has a userID){
        //load user info / log the user in
    }
    

    然后你的用户就不必再次登录他的手机,除非你添加一些额外的逻辑来记住他们第一次登录应用程序并让它在一周后过期。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-17
      • 2017-06-19
      • 1970-01-01
      • 2011-06-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多