dougaimian1143 2016-11-11 16:22
浏览 47

使用会话cookie Android应用程序维护服务器会话

i'm having a problem with my session check.
The first time i log in i call the php login script in which i call session_start(), check with the DB if username and password are correct and in this case store $_SESSION["username"] and $_SESSION["id"] variables and retireve $id variable that is session_id();

Then i'm on the homepage of my app (that i want to protect if no session is opened), so in onRestart method of this home activity i call the checkLogin() function that runs the CheckLogin php script in which i call session_start(), $id=session_id() and check if(isset($_SESSION["username"]) and isset($_SESSION["id"]) and $_SESSION["id"]==$id). In this case i retrieve echo 'logged' else 'error'

I saw that in my php.ini (using mysite/phpinfo.php) session.gc_maxlifetime is set to 1440 seconds but my CheckLogin script says that i'm still connected even if 8 hours passed. When i first login i save the session_id() in my sharedPreferences and then i pass this id in the checklogin request as Cookie paramether in this way

HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setReadTimeout(15000);
        conn.setConnectTimeout(15000);
        conn.setUseCaches(true);
        conn.setRequestMethod("POST");
        conn.setDoInput(true);
        conn.setDoOutput(true);
        conn.setRequestProperty("Cookie","PHPSESSID="+id);

Please can anyone explain me why $_SESSION variables are still there 8 hours of inactivity later even if in php.ini maxlifetime is set to 1440?
Thank you in advance.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能
    • ¥15 jmeter脚本回放有的是对的有的是错的
    • ¥15 r语言蛋白组学相关问题