-1

I've been getting an unidentified index error on one of the files. I use XAMPP to run locally and am working on this site with another developer who uses MAMP on a MAC who does not receive this error. I assume the code is wrong and I am supposed to see this error and that it does not on his because of different php permissions on mamp, but do not know where to start in resolving it. Keep in mind I am still very new to php.

I am getting this error:

Notice: Undefined index: uidentifier in C:\xampp\htdocs\boone-web\templates\basic\index.php on line 38

Here is what it's referring to:

            <ul>
                <?php if($_SESSION['uidentifier'] == 1) : ?>
                    <li><a href="<?php echo BASE; ?>">Home</a></li>
                    <li><a href="classJournals.php">Student Journals</a></li>
                    <li><a href="logout.php">Logout</a></li>

                <?php else : ?>
                    <li><a href="<?php echo BASE; ?>">Home</a></li>
                    <li><a href="profile.php">My Profile</a></li>
                    <li><a href="map.php">Game Map</a></li>
                    <li><a href="journal.php">MyJournal</a></li>
                    <li><a href="highScores.php">High Scores</a></li>
                    <li><a href="logout.php">Logout</a></li>
                <?php endif; ?>
            </ul>
  • be sure you have an entry named uidentifier in your array $_SESSION – ScaisEdge Oct 21 '16 at 19:40
  • Maybe the other developer doesn't have all error reporting turned on in his environment and dont see notices. – JimL Oct 21 '16 at 19:41
  • You're likely going to get blasted because this type of question is asked hundreds of times, but scaisEdge is right, you aren't checking if the var exists prior to using it. `if ((exists($var)) && ($var ==1){` – Duane Lortie Oct 21 '16 at 19:43
  • I knew I was in for it after seeing all of the similar questions. Thank you all for the quick responses though. First time poster here, ya'll are awesome! – Austin Hardesty Oct 21 '16 at 19:55

2 Answers2

0

You can solve this by using isset

<?php if(isset($_SESSION['uidentifier']) && $_SESSION['uidentifier'] == 1) : ?>
cmorrissey
  • 8,493
  • 2
  • 23
  • 27
0

First is just a warning message...you should check for the $_SESSION['uidentifier'] first:

<ul>
   <?php if(isset($_SESSION['uidentifier'])) : ?> 
   <?php if($_SESSION['uidentifier'] == 1) : ?>
      <li><a href="<?php echo BASE; ?>">Home</a></li>
      <li><a href="classJournals.php">Student Journals</a></li>
      <li><a href="logout.php">Logout</a></li>
   <?php else : ?>
       <li><a href="<?php echo BASE; ?>">Home</a></li>
       <li><a href="profile.php">My Profile</a></li>
       <li><a href="map.php">Game Map</a></li>
       <li><a href="journal.php">MyJournal</a></li>
       <li><a href="highScores.php">High Scores</a></li>
       <li><a href="logout.php">Logout</a></li>
   <?php endif; ?>
   <?php endif; ?>
</ul>
Hackerman
  • 12,139
  • 2
  • 34
  • 45