I’m wondering why WordPress does not support sessions and many people out there claim that putting the following code in functions.php might not be a good idea (it in fact works for me but returns PHP warnings, too):
function cp_admin_init() {
if (!session_id())
session_start();
}
add_action(âinitâ, âcp_admin_initâ);
Is it good idea to enable sessions in WordPress? What would be the correct way to do this?
The reason for not working
$_SESSIONS
in WP Core:The thing WordPress is doing with sessions is burdened inside
~/wp-includes/load.php
.The responsible function for resetting the
$_SESSION
tonull
iswp_unregister_GLOBALS()
. So in case you really need it, you’ll have to turnregister_globals
off in yourphp.ini
file.The idea behind it?
– by @TomJNowell in the comments.