Cookie-> set not working when calling a route using file_get_contents?


Setting cookie functionality is not working when I'm calling a route fro PHP filegetcontents method? and It's working with jQuery $.ajax. What is the mistake i've done? Please help me to solve this.


$api->addGet('/setmycookie/{cookievalue}', array('controller' => 'myController', 'action' => 'index'));


public function indexAction($cookievalue) { session_start();
$this->cookies->set('myCookie', $cookievalue, time() + 15 * 86400); $this->cookies->send(); $this->response->setResponse(array("status" => "success")); return $this->response; }

Front End Trigger:

$data = filegetcontents("");

edited Jul '16

So, you would expect that file_get_contents will accept data from Set-Cookie HTTP header? Where it would store it? That is not client but one PHP process initiating remote call to another HTTP server / PHP. That's why your AJAX works, since that's client side (i.e. cookie is stored in a browser of a client).