'CI->session->userdata['email'] Undefined Index
### I'm running a PHP script on Web Hosting and continue to receive errors like: ###
A PHP Error was encountered Severity: Notice
Message: Undefined index: email
Filename: helpers/wpu_helper.php
Line Number: 7
Backtrace:
File: /storage/ssd5/423/13712423/public_html/application/helpers/wpu_helper.php Line: 7 Function: _error_handler
File: /storage/ssd5/423/13712423/public_html/application/controllers/Admin.php Line: 9 Function: is_logged_in
File: /storage/ssd5/423/13712423/public_html/index.php Line: 315 Function: require_once
helpers/wpu_helper.php
`function is_logged_in() { $CI =& get_instance();
if (!$CI->session->userdata['email']) {
redirect('auth');
} else {
$role_id = $CI->session->userdata['role_id'];
$menu = $CI->uri->segment(1);
$queryMenu = $CI->db->get_where('user_menu', [
'menu' => $menu
])->row_array();
$menu_id = $queryMenu['id'];
$userAccess = $CI->db->get_where('user_access_menu', [
'role_id' => $role_id,
'menu_id' => $menu_id
]);
if ($userAccess->num_rows() < 1) {
redirect('auth/blocked');
}
}
function check_access($role_id, $menu_id)
{
$CI = get_instance();
$result = $CI->db->get_where('user_access_menu', [
'role_id' => $role_id,
'menu_id' => $menu_id
]);
if ($result->num_rows() > 0) {
return "checked='checked'";
}
}
}`
Solution 1:[1]
Change your code to :
if (!this->session->userdata('email')) {
redirect('auth');
} else {
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | TV-C-1-5 |