Jump to content

isset not reading variable


michaelpina

Recommended Posts

Can someone help me understand :confused: why when I run this script I can see that {$_SESSION['user_level']} has changed for each user I login into for, but, for some reason the elseif statement never gets executed although I can see thru the debug line of i inserted (line 4: echo statement for user_level) does show that the 'user_level' variable does equals '1'? WHY?

 

How come only the 'first_name" If  statement executes and never the elseif?

 

<?php   //  Changing Header Due to User Status     


// Add links if the user is an administrator:  


if ( isset($_SESSION['first_name'])) {  

    echo 'Welcome user';
    echo ", {$_SESSION['first_name']}!";     
echo ", {$_SESSION['user_level']}!"; 
    echo '<a href="../registration/login/logout.php" title="Logout"> | Logout</a>
    <a href="../registration/login/change_password.php" title="Change Your Password"> | Change Password</a>
    <a href="../addevent/" title="My Events"> | My Events</a>
    <a href="../addvenue/" title="My Places"> | My Places</a>
    <a href="../registration/login/register.php" title="Register for the Site"> | Register</a>
    <a href="../registration/login/forgot_password.php" title="Password Retrieval"> | Retrieve Password</a>
';

} 

elseif ( isset($_SESSION['user_level']) == '1' ) { 

    echo 'Welcome Admin';
    echo ", {$_SESSION['first_name']}!";     
//   echo ", {$_SESSION['user_level']}!";
    echo '<a href="../registration/login/logout.php" title="Logout"> | Logout</a>
    <a href="../registration/login/change_password.php" title="Change Your Password"> | Change Password</a>
    <a href="../addevent/" title="My Events"> | My Events</a>
    <a href="../addvenue/" title="My Places"> | My Places</a>
    <a href="../registration/login/register.php" title="Register for the Site"> | Register</a>
    <a href="../registration/login/forgot_password.php" title="Password Retrieval"> | Retrieve Password</a>
';
    echo '<a href="view_users.php" title="View Users">  | Users</a>
    <a href="../registration/login/view_activities_types.php" title="All Activity Choice Types">  | Activity Choices</a>
    <a href="../registration/login/admin/add_activity_type.php" title="Add Activity Choices"> | Add Activity Choices</a>
';

}

else {

//  echo ", {$_SESSION['user_level']}!";

}

Link to comment
https://forums.phpfreaks.com/topic/230497-isset-not-reading-variable/
Share on other sites

Sorry I hadn't placed my header ... here it is ... the idea sounded good until I actually revised the file this evening and saw that I have indeed initiated the session in an earlier part of the pages code. :(

 

<?php # script 1.1

// This begins the HTML header status for the site.

// Start output buffering:
ob_start();

// Initialize a session:
session_start();


// Check for a $page_title value:
if (!isset($page_title)) {
    $page_title = 'User Registration';
}


?>  

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.