elkarte / Elkarte

ElkArte Forum. A free, open source, modern discussion forum / BB
https://elkarte.github.io/Elkarte/
BSD 3-Clause "New" or "Revised" License
175 stars 61 forks source link

2.0 'Undefined array key "globalCookies"' #3686

Closed sbulen closed 1 year ago

sbulen commented 1 year ago

Describe the bug 'Undefined array key "globalCookies"' upon disabling global cookies & enabling local cookies.

ElkArte info

  1. What ElkArte version are you using? current GH
  2. What version of PHP are you running? 8.0
  3. MySQL or PostgreSQL and what version? MS 8.0

To Reproduce Steps to reproduce the behavior:

  1. Disable global cookies
  2. Enable local cookies
  3. Press SAVE

Screenshots image

sbulen commented 1 year ago

Problem exists in 1.1.8 & 2.0.

Spuds commented 1 year ago

Arh!

Spuds commented 1 year ago

Can you confirm the error was on line 222? it should be in the admin error log. I can get a similar error on 1.1.8/7.4 but my local 1.1.9/8.1 and 2.0/8.1 are not tossing it (but to note what is on my local is more recent than the repo atm)

Spuds commented 1 year ago

Well .... Looks like we may have some a common problem(s) in that area.

First up

        // Local and global do not play nicely together.
        if (!empty($_POST['localCookies']) && empty($_POST['globalCookies']))
            unset ($_POST['globalCookies']);

Looks a bit odd, why unset the value if its already empty? Seems like the intention was to unset globalCookies should localCookies be enabled. One could probably drop the second empty check (I don't think unset will care) or negate the second empty.

Second one is just for fun. Empty out the cookie name (I don't think it matters if local or global are set) and save. You will be logged out and when you try to log back in Fatal error: Uncaught ValueError: setcookie(): Argument #1 ($name) cannot be empty in /var/www/smf21/Sources/Subs-Auth.php:883 Then reach for your db tools or repairsettings 🤯

sbulen commented 1 year ago

ManageServer.php, line 300. I am current with the development branch.

Oddly, I couldn't reproduce it on php8.1.

After switching back to php8.0, I saw it again. This might be specific to 8.0, not 8.1.

Spuds commented 1 year ago

Yup, that is the same line, 2.0 vs 1.1 ... seems like a 8.0 issue where unsetting an array key that does not exist (in an array that does exist) raises an error. Its that incorrect empty check I referenced in the previous note that would prevent that. Oh Joy

Spuds commented 1 year ago

https://github.com/elkarte/Elkarte/pull/3698/commits/609496c088e5a0d6cebf6a6fe4c542b22aa35167