CodeIgniter Forums
Cookie Path – "default" setting overrides explicit "/" - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forum-31.html)
+--- Thread: Cookie Path – "default" setting overrides explicit "/" (/thread-72557.html)



Cookie Path – "default" setting overrides explicit "/" - bivanbi - 01-05-2019

Good day,

situation is this:
 - have a default cookie path of /path, because ci_session should not be accessible outside /path
 - need to set a cookie from CI with path of "/" – this cookie needs to be accessible site-wide, for another web application to work
 - using CI's response->setCookie().. to set this cookie, specifying '/' as cookie path
 - System\HTTP\Response:ConfusedetCookie overrides cookie path even if it is explicitly set to '/' by the caller. 

I think this is not how it should behave. I suggest CI should only use default path when path  is not set (or set to null) by caller.

Am I on the wrong track here?

code snippet from: CI4 4.0.0 alpha 4 Response class:
public function setCookie(
  $name,
  $value = '',
  $expire = '',
  $domain = '',
  $path = '/',
 
$prefix = '',
  $secure = false,
  $httponly = false
)

{
(...)
if ($path === '/' && $this->cookiePath !== '/')
{
  $path = $this->cookiePath;
}


How I think it should be:
public function setCookie(
  $name,
  $value '',
  $expire '',
  $domain '',
  $path null,
 
 $prefix '',
  $secure false,
  $httponly false
)

{
(...)
if (null === $path)
{
  $path $this->cookiePath;
}


(While debugging the situation, I found a typo in the PHPDoc of the function, on line 810Smile
* Accepts an arbitrary number of binds (up to 7) or an associateive