- Edited
Log's barking about this one:
if (isset($_SESSION['userid']) && $_SESSION['userid']) return $_SESSION['userid'];
I'm thinking that if isset() is falsy then the logical AND makes it evaluate the session variable anyway, so "undefined array key"? Is that correct?