功能设置$ _SESSION中的所有$ _COOKIE变量都不起作用

function cookiesToSession()
    {
        foreach($_COOKIE as $key => $value)
        {
            $_SESSION[$key] = $value;
        }
    }

Hi everyone, the above code doesn't work. The goal was to have for any $_COOKIE['var'] an automatic setting of $_SESSION['var'].

Any ideas about what went wrong ? Thanks in advance.

Did you call session_start() prior to this function? Did you remember to call this function? (I've done that before: write a function and then forget to actually call it!).

If neither of those are the issue, check that session saving is properly configured - does the savepath exist? Is the session cookie domain/path valid? That sort of thing.