Using a cookie as a variable in a Switch statement in PHP

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":

case "User":

case "Library":
    echo "yes";
    echo "no";

Guys! 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, wasted 4 or so hours on this lol.

btw thanks for the solutions.

Source: wampserver

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.