Create lifetime cookie fails

I have made a Cookie consent solution by my own with Kirby Cookies. However, when I use this:

<?php Cookie::forever('consent', get('consent')); ?>

It works on localhost, but not on my server, I get this error:

Argument 1 passed to Kirby\Http\Cookie::lifetime() must be of the type int, float given, called in .../kirby/src/Http/Cookie.php on line 45

But this works. Have I done something wrong?

<?php Cookie::set('consent', get('consent')); ?>

What does get('consent') return? Note that the second argument needs to be a string, but that doesn’t explain your specific error message.

get('consent') returns a simple string ‘essential’ or ‘analytics’. But I think that doesn’t make any problems.

I think this might be the issue:

If PHP encounters a number beyond the bounds of the int type, it will be interpreted as a float instead. Also, an operation which results in a number beyond the bounds of the int type will return a float instead.

The size of an int is platform-dependent, although a maximum value of about two billion is the usual value (that’s 32 bits signed). 64-bit platforms usually have a maximum value of about 9E18. PHP does not support unsigned ints. int size can be determined using the constant PHP_INT_SIZE , maximum value using the constant PHP_INT_MAX , and minimum value using the constant PHP_INT_MIN .

https://www.php.net/manual/en/language.types.integer.php

That might be the error. So wouldn’t it make sense to include something in this function to prevent that Kirby is totally broken when using this function on a 32 bit system? Something like a if / else clause https://www.php.net/manual/de/function.is-float.php

Maybe I should open a Github Issue?

The lifetime is given as a UNIX timestamp, if this timestamp is beyond the size allowed on your system, it will fail. I guess Kirby could check if the given number is an integer, but in this case, the forever function would not work as expected, either.

It won’t hurt to create an issue, let’s see what the devs say.

All right, done :slight_smile: