node-php icon indicating copy to clipboard operation
node-php copied to clipboard

only last cookie is sent

Open meaninglessidentifier opened this issue 8 years ago • 1 comments

if php's setcookie is called multiple times per response, only the last cookie will be included in the response.

for example, the response from the following php code will include only the "bbb" cookie.

<?php
setcookie("aaa", "xxx");
setcookie("bbb", "zzz");

for contrast, the following express code works as expected.

var express = require('express');
var app = express();
app.get('/', function(req, res){
  res.cookie('aaa', 'zzz');
  res.cookie('bbb', 'xxx');
  res.send('z');
});
app.listen(9090);

this prevents wordpress from functioning as its authentication process sets multiple cookies in a single request. (cf wp_set_auth_cookie in wp-includes/pluggable.php.)

i have tried using the version of node-php currently available from npm as well as the current head on github with the same results. am i doing something wrong?

edit: in case it's relevant, here is the code that i am using to start the server:

var express = require('express');
var php = require("node-php");
var app = express();
app.use("/", php.cgi(__dirname+"/cookietest"));
app.listen(9090);

edit2: and just in case this is relevant...

$ php-cgi --version
PHP 5.5.9-1ubuntu4.20 (cgi-fcgi) (built: Oct  3 2016 13:02:14)
...

edit3: i've also confirmed that the above php code works as expected when served by invoking the php executable as follows

$ php -S 127.0.0.1:9090 -t ./cookietest/

meaninglessidentifier avatar Dec 16 '16 22:12 meaninglessidentifier

Fixed with pull request https://github.com/mkschreder/node-php/pull/19

addyh avatar Sep 01 '17 04:09 addyh