doushi1510 2016-10-29 23:00
浏览 33

php没有创建唯一的会话

I am having a problem with my mvc framework, my entire site is using a single session id so when I log in using my pc as soon as i visit the site with another device that device uses that same session , Does anyone know where the problem might be this is the code inside my sessions.php file where sessions are set

public static function set($value,$key)
{    
    $_SESSION[$key] = $value;
}

And below is my login function

   $email = $_POST['email'];
   $password = $_POST['password'];
   $password = md5($password);
   $statement = $this->db->prepare("SELECT * FROM users WHERE email=:email AND password=:password");
   $statement->execute(array(':email'=>$email,':password'=>$password));

   $results = $statement->fetch(PDO::FETCH_ASSOC);
   $count = $statement->rowCount();

   if ($count>0) {
       $id = $results['id'];
       session::init();
       session::set($id,"id");

       echo json_encode(array('status'=>true));
   }
  • 写回答

1条回答 默认 最新

  • dongzhanjuan5141 2016-10-29 23:44
    关注

    You have...

    session::set($id,"id");
    

    And your function, once more..

    public static function set($value,$key)
    {    
        $_SESSION[$key] = $value;
    }
    

    You're setting the key of "id" to whatever the "id" is of the record in the database. There's no reason for this value to change, unless you change it in the database.

    评论

报告相同问题?

悬赏问题

  • ¥15 求一下解题思路,完全不懂
  • ¥15 tensorflow
  • ¥15 densenet网络结构中,特征以cat方式复用后是怎么进行误差回传的
  • ¥15 STM32G471芯片spi设置了8位,总是发送16位
  • ¥15 R语言并行计算beta-NTI中tree文件的类型
  • ¥15 如何解读marsbar导出的ROI数据?
  • ¥20 求友友协助弄一下基于STC89C52单片机的声光控制灯原理图
  • ¥15 arduino双向交通灯设计
  • ¥15 有没有会粒子群算法的大能(○゜ε^○)求带不会出收敛图😭
  • ¥15 Matlab读取根元素出错