doukun0888 2015-09-04 18:03
浏览 94

使用多个PHP处理PHP servlet的会话

I am developing a game for android which uses PHP servlets to access a database. They are multiple PHP files. My android application asks the PHP files for data stored in the database. I'm trying to implement some kind of session control for my PHP servlets. In the PHP referent to the user login(login.php), I added

session_start();
    // set time-out period (in seconds)
    $inactive = 1800;

    // check to see if $_SESSION["timeout"] is set
    if (isset($_SESSION["timeout"])) {
            // calculate the session's "time to live"
            $sessionTTL = time() - $_SESSION["timeout"];
            if ($sessionTTL > $inactive) {
            session_destroy();
            echo "fazer_login_novamente";
            }
    }   

    $_SESSION["timeout"] = time();
    while($row=mysql_fetch_assoc($result)){
        $json[]=$row;
    }

Right after the user succeeds on logging in. Now, after logging in, the application asks for words stored in the database by connecting to another PHP file. This new php (words.php) checks if the user has already started a session or if it's some king of hijacking through the checkSession PHP function of this link:http://php.net/manual/pt_BR/function.session-regenerate-id.php

BUt it seems the user always gets the exception "no session started" when connecting to words.php.

What am I doing wrong? Can you help me?

EDIT: here's a link to words.php: https://www.dropbox.com/s/23em2h3l3hj1via/login.php?dl=0

EDit: here's a link to login.php: https://www.dropbox.com/s/1hp6udivy8whvl8/words.php?dl=0

  • 写回答

1条回答 默认 最新

  • dongquweng5152 2015-09-04 18:14
    关注

    Maybe, in login.php add a variable like

    $_SESSION['session_set']=true;
    

    And, in words.php, do this:

    session_start();
    if(isset($_SESSION['session_set']) {
        //session set (by login.php)
    }
    else {
        //session not set (by login.php)
    }
    

    You have to know that at the start of each php file you have to use session_start(); to access the $_SESSION variable.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用