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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题