Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create lifetime cookie returns a error #2968

Closed
Werbschaft opened this issue Dec 3, 2020 · 11 comments · Fixed by #3046
Closed

Create lifetime cookie returns a error #2968

Werbschaft opened this issue Dec 3, 2020 · 11 comments · Fixed by #3046
Assignees
Labels
type: bug 🐛 Is a bug; fixes a bug
Milestone

Comments

@Werbschaft
Copy link

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

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

It works on localhost, but not on the hosting for the customer (Host Europe), 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.

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

As reference, please check this thread at the forum. Is there a way to avoid this? Not sure if this is a bug or only a slow hosting problem. However, if I use the forever function, the site will not work.

https://forum.getkirby.com/t/create-lifetime-cookie-fails/20228/4

@bastianallgeier
Copy link
Member

@lukasbestle any idea how this is even possible? Looking at the cookie code, I have no idea how the lifetime can become a float.

@afbora
Copy link
Member

afbora commented Dec 3, 2020

@bastianallgeier This issue caused from following line:
https://github.com/getkirby/kirby/blob/master/src/Http/Cookie.php#L107

253402214400 is exceeds the maximum integer value at 32 bits and it's float on 32-bit.

I think, it should be like that:

$options['lifetime'] = PHP_INT_MAX;

Note: @texnixe has already found the source of the issue on the forum 😅

@Werbschaft
Copy link
Author

Is this the End of the Unix Timestamp in 2038 (Y2K38)? I think the robots will take over the world anyway, so why don't we put it on that date? 🤯

@lukasbestle
Copy link
Member

lukasbestle commented Dec 3, 2020

I think it should be this so we can keep the nice 9999-31-12 date on 64-bit machines:

$options['lifetime'] = min(253402214400, PHP_INT_MAX); // 9999-12-31 if supported (lower on 32-bit servers)

@lukasbestle lukasbestle added this to the 3.5.1 milestone Dec 3, 2020
@Werbschaft
Copy link
Author

Werbschaft commented Dec 3, 2020

@afbora @lukasbestle I have tested both methods on a 32 bit system and both work. It is up to you which solution seems to be the better one. @lukasbestle very elegant solution for both cases!

@bastianallgeier
Copy link
Member

Is this the End of the Unix Timestamp in 2038 (Y2K38)? I think the robots will take over the world anyway, so why don't we put it on that date? 🤯

🤣

@lukasbestle
Copy link
Member

lukasbestle commented Dec 4, 2020

Let's hope there aren't any 32-bit servers by 2038. 😅

@bastianallgeier
Copy link
Member

@lukasbestle wait! You live in Germany too, right? You really believe there won't be any 32-bit severs by 2038?

@afbora
Copy link
Member

afbora commented Dec 4, 2020

@Werbschaft
Copy link
Author

New name suggestions, maybe better words for forever

Cookie::untilCollapse(string $key, string $value, array $options = [ ]): bool

Cookie::untilTheEndOfTheWorld(string $key, string $value, array $options = [ ]): bool

Cookie::asLongAsYourOperatingSystemRuns(string $key, string $value, array $options = [ ]): bool

@afbora afbora self-assigned this Jan 4, 2021
afbora added a commit that referenced this issue Jan 4, 2021
@afbora afbora linked a pull request Jan 4, 2021 that will close this issue
4 tasks
afbora added a commit that referenced this issue Jan 4, 2021
…it servers #2968

Improve `Cookie::lifetime()` method #2968

Add float and invalid test for cookie lifetime #2968
afbora added a commit that referenced this issue Jan 4, 2021
afbora added a commit that referenced this issue Jan 4, 2021
Revert back lifetime() method changes #2968

Remove not viable test #2968
lukasbestle added a commit that referenced this issue Jan 4, 2021
Improves `Cookie::forever()` method for 32-bit servers #2968
@lukasbestle
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🐛 Is a bug; fixes a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants