I have a piece of code on a website I am building that allows for a link to an administator page to be accessed when an admin logs in. I have this piece of code:
<?php
$arrayAdmin = array(6, 12);
if (in_array($_SESSION['userId'], $arrayAdmin))
{echo '<a href="./addstuff.php">Admin</a>';}
if (isset($_SESSION['userId']))
{echo '<p>You are logged in!</p>'; }
else { }
?>
When a non admin account logs in it works and when an admin logs in it shows the link correctly but when no user is logged in it states:
Notice
: Undefined index: userId in /home/mahs_rgeyer/www/index.php on line 63
If I remove the inarray no error message is shown, and if i remove just the isset the error message is shown. I have attempted to move the code around but to no avail. I just don't understand why it always shows this error message when no user is logged in but works exactly as intended when someone logs in.