Page 1 of 1


Posted: Fri Jun 07, 2019 5:00 pm
by radyk
I am testing the use of cookies and I am having some issues. I thought the following statements would result in "123" being put in the phpbb3_9e25h_poster2 cookie but instead, when I am reading the cookie previously set, it is blank. Does anyone know why?

$user->set_cookie('poster', "123", time() + 120);
$rad3 = request_var($config['cookie_name'] . '_poster', '', false, true);
$user->set_cookie('poster2', $rad3, time() + 120);

Cookie results below:

phpbb3_9e25h_poster 123 localhost / 2019-06-07T16:44:47.010Z 22 ✓
phpbb3_9e25h_poster2 localhost / 2019-06-07T16:44:47.010Z 20 ✓

In the above I expected "123" in poster2 cookie.

Re: request_var

Posted: Fri Jun 07, 2019 5:50 pm
by EA117
The reason is because set_cookie() is building Set-Cookie directives to be included in the HTTP headers of a still-in-progress HTTP response being constructed by the PHP code.

Until the HTTP response has been completed and sent back to the HTTP client, there has not yet been an opportunity for that cookie to be saved, nor for that cookie to have been sent as part of any future HTTP request. Only cookies that had been successfully saved during a previous HTTP response would have been present in the current HTTP request that request_var() is letting you examine.

Re: request_var

Posted: Sat Jun 08, 2019 11:57 am
by mrgoldy
Moreover, I would suggest to not use request_var().
Use the request class (\phpbb\request\request) instead.

$rad3 = $request->variable($config['cookie_name'] . '_poster', '', false, \phpbb\request\request_interface::COOKIE);