This snippet of code is suppose to compare the value of the $_COOKIE
variable and move forward accordingly but instead I am getting the error
Undefined index = type
Here is the code -
if ($result != false) {
$session_data = array(
'username' => $result[0]->username, //THIS WAS PREVIOUSLY user_name
'password' => $result[0]->password,
'type' => $result[0]->type,
);
// Add user data in session
$this->session->set_userdata('logged_in', $session_data);
if (in_array($_COOKIE['type'], array("Admin", "User", "Library")))
switch ($_COOKIE['type']) {
case "Admin":
$this->load->view('admin_page');
break;
case "User":
$this->load->view('viewtry');
break;
case "Library":
echo "yes";
break;
default:
echo "no";
}
****UPDATE****
I solved my problem, what I did was just replaced the two instances of $_COOKIE['type']
with simply the variable $type
as I declared it earlier. Kinda stupid of me to overlook that.
Thanks for the solutions.
$COOKIE
doesn't havetype
key. So, before get value of thetype
, you should check that thetype
was defined or not. You can use the function that is calledisset
for checking key.