Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setcookie() expects parameter 3 to be integer, array given

Tags:

php

cookies

I am getting this PHP error:

PHP Warning: setcookie() expects parameter 3 to be integer, array given

With this code:

$setResult = setcookie(
    'visitorId',
    "{$newIdForNewVisitor}",
    [
        'httponly' => true,
        'expires' => time() + (50 * 365 * 24 * 60 * 60)
    ]
);

But on the 2nd example of the setcookie documentation, I see that the options parameter on argument 3 can take an associative array:

An associative array which may have any of the keys expires, path, domain, secure, httponly and samesite. The values have the same meaning as described for the parameters with the same name. The value of the samesite element should be either Lax or Strict. If any of the allowed options are not given, their default values are the same as the default values of the explicit parameters. If the samesite element is omitted, no SameSite cookie attribute is set.

What mistake is being made here?

like image 857
Sean D Avatar asked Aug 07 '19 20:08

Sean D


1 Answers

You may need to check which version of PHP you are running. The alternative signature of the setcookie function was only added in PHP version 7.3.0.

like image 69
Omer Siddique Avatar answered Oct 31 '22 16:10

Omer Siddique