Is this bad practice?
if ($_SESSION['something'] == '')
{
echo 'the session is empty';
}
Is there a way to check if its empty or it is not set? I'm actualy doing this:
if (($_SESSION['something'] == '') || (!isset($_SESSION['something'])) {
echo 'the session is either empty or doesn't exist';
}
Does !isset
just checks if a $_SESSION['']
exist and doesn't check if, is there are values in the array or not
I would use
isset
andempty
:array_key_exists
is a nice alternative to usingisset
to check for keys:Make sure you're calling
session_start
before reading from or writing to the session array.