[nycphp-talk] cookies and experiation

Margaret Waldman mmwaldman at
Sun Jul 10 09:56:30 EDT 2011

I wanted to create a cookie that basically never expires.

time() + x

We can live to say 100 or so, so say 125 years expiration would be good.

time() + 3944700000

But that number is too big.

Intval says on a 32 bit machine max is 2147483647.

So 2147483647 – time() = 4294967294, which is bigger than 2147483647

2147483647 = 68 years but because I’m adding time it grows bigger than the bigger integer

But I really can only do this 2147483647  - time() = 837178076 26 years

But php wasn’t crapping out on 290000000 + time(), so what really is the biggest integer

Time today =            1310305571
Time tomorrow =     1310391971
Next year will be =   1341863171 (42 years)
In 20 years will be = 1372420841 (52 years)

So, 2147483647 – time in 20 year (1372420841) = 775062806 approx 23 years

The numbers don’t look quite right but at time increases the life time you can extend in ints decreases.

So, instead of just adding a value to time, I should

$newLife = 2147483647  - time();

setcookie(“name”, “val”, time() + newLife);

I’m sure by the time, time() grows to be so big that this formula is an issue, integers will be big enough to handle it?

Anyway, does anyone know the real max size of an integer? Cause it ain’t 2147483647 like the docs say for a 32 bit machine.

Margaret Michele Waldman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the talk mailing list