0

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.

Route:

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

Controller:

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("http://domain.com/api/setmycookie/mycookievalue");
  • 2
    the cookie is likely being sent out from the server as a header as it should. file_get_contents doesn't handle/parse headers though. You would need to handle that yourself or [use something like curl](http://stackoverflow.com/questions/1797510/file-get-contents-receive-cookies). – Jonathan Kuhn Jul 06 '16 at 17:47
  • 1
    @teckiez, I googled this and found the following solution: http://stackoverflow.com/questions/3431160/php-send-cookie-with-file-get-contents – Timothy Jul 07 '16 at 14:27
  • Timothy's solution is worth a try. Please do so and tell us how it went :) – Nikolay Mihaylov Jul 09 '16 at 10:42

0 Answers0