Jump to content

$input->cookie->set() never saves cookie


suntrop
 Share

Recommended Posts

I changed my default setcookie() functions to the newly added $input->cookie method as described in https://processwire.com/blog/posts/pw-3.0.141/

Just noticed no cookies are saved when using PW's $input->cookie->set() (in template file). I am using PW 3.0.148, PHP 7.3 and testing with setcookie('test', 'test') works just fine. Tried to add age, path and domain as well, but nothing works.

setcookie('defaultsetcookie', 'works');

$config->cookieOptions = [
  'age' => 604800,
  'path' => null,
  'domain' => null,
  'secure' => null,
  'httponly' => false,
  'fallback' => true
];

$c = $input->cookie->set('pwcookie', 'wontwork');
print_r( $c );
print_r( $_COOKIE );

Output

ProcessWire\WireInputDataCookie Object
(
    [defaultsetcookie] => works
    [wire] => 89ortkjmq5dsgb7em2h6ljod9v
    [pwcookie] => wontwork
)
Array
(
    [defaultsetcookie] => works
    [wire] => 89ortkjmq5dsgb7em2h6ljod9v
    [pwcookie] => wontwork
)

Any idea what is wrong? It is strange setcookie() works but PW methods won't.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...