문제

I was trying to minimize the db hits by storing data in session when the session starts and then return the data from the session for the subsequent requests. But It looks like it is not working as I expected

See test remote method below

update: added session_start() which I missed to copy

Main.php - Service class

class Main{
      public function amfRequest(){
         session_start();
         $test = new Test();
         return $test->testSession();
      }
  }

Test.php

class Test(){
     public function testSession(){
     if (!isset($_SESSION['test'])){
        return "setting sesion variable";
        $_SESSION['test'] = "all set!";
    }else{
        return "getting session variable";
           }                
      }

}

Expected result

  • 1st run - return setting sesion variable
  • subsequent runs - return getting session variable

But it is always returns setting sesion variable

Does AMF PHP destroys the session every time I request? if so, how to handle sessions then?

도움이 되었습니까?

해결책

Answer is NO. The results I was getting because the session was destroyed somewhere else in the code, thus I was always getting isset($_SESSION['test']) as false.

다른 팁

Basic codding info. Workflow breaks in return. so $_SESSION['test'] = "all set!"; newer gets call.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top