Question

I run followed test to verify my code working properly:

curl -L -i -X POST -d 'json={"orderBy":0,"maxResults":50}' http://mysite.com/ctlClient/

I call: http://mysite.com/ctlClient/index.php:

        session_unset();
        session_start();

        //pass data to _SESSION
        foreach($_POST as $key => $value){
           $_SESSION[$key] = $value;
         }
        // redirect to `/fwf/online/index.php`
        ctlGotoSameDomain("/fwf/online/");

After redirect, I call /fwf/online/index.php:

 <?php

session_start();

 ....

class fwfOnline {


  public function __construct() {

         msqLogFile('test/test_max',$_SESSION);

        // here is my problem, $_SESSION is empty, :(

        $this->json = isset($_SESSION['json']) ? $_SESSION['json'] : null;
        global $gConfig;
        if ($gConfig['soapDebug'])
            msqLogFile("fwf/post", Array('post' => 'Request: '.$this->json));
        $this->response = $this->getResponse();
        echo $this->response;
    }

....

In logs from mysite.com/ctlClient/index.php I see that $_SESSION has data but in /fwf/online/index.php its empty.

Can someone tell me what did i miss?

Thank you,

[EDIT] From @rr-

I printed both session IDs and got difference:

"2013-07-05 09:44:31","Session ID: ihpfs1skrp792gncgancb02516"
"2013-07-05 09:44:31","Session ID: tp6ejtl1tj9bigrgsi3jt6h9a1"

why its happened?

[FIX]

Regards to @rr- answer I found the problem,

I need to add -b to my script to enable the cookies. CURL by default doesn't use them and this issue caused to session ID problem.

Thank you rr-

Was it helpful?

Solution

Make sure you have started session in the target page: /fwf/online/index.php.

You can also check return value of session_id() on both pages. The value should be the same, if it isn't even though you have called session_start on both pages, this can mean three things:

  1. Either you call session_write_close which effectively leads to creating new sessions and forgets all previous data,
  2. PHP cannot access directory where it should store session data on the server (it happens!),
  3. ...or user has disabled cookies, thus making his browser unable to keep session ID.

I think the third option is most likely the reason of the problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top