0

I have a website in which sessions gets created as per query string parse to the URL. I am reading session value and accordingly want to change header of the website. Things working fine with below code but it is not going inside elseif condition. If I try to print session value it gives me correct echo but condition is not working properly. It works with If and else but not going inside ElseIf

<?php
    $clientID = "";
    $cid = $_GET['ciid'];
    $storeTitle = "";
    $storeDLogo = "";
    $storeGDlogo = "";
    $storeGMlogo = "";
    if (isset($_GET['ciid'])) {
        session_start();
        $_SESSION["mycid"] = $cid;
        $clientID = $_SESSION["mycid"];
    }


    //for FIEO
    if (isset($_SESSION["mycid"]) == "14"){
        $storeTitle = "Federation of Indian Exports Organization BrandSTORE";
        $storeDLogo = "/images/hid/figo-14.jpg";
        $storecolor1 = "#02ADF2"; //applied in header background
        $storecolor2 = "#FF9304"; //applied in mini header background 
        $storeGDlogo = "/images/hid/gl-14.jpg";
        $storeGMlogo = "/images/hid/gl-m-14.jpg";
    } elseif (isset($_SESSION["mycid"]) == "7"){ 
        $storeTitle = "Jet Airways BrandSTORE";
        $storeDLogo = "/images/jetAirwaysLogo.jpg";
        $storecolor1 = "#000"; //applied in header background
        $storecolor2 = "#FF9304"; //applied in mini header background 
        $storeGDlogo = "/images/globaJLinkerLogo.jpg";
        $storeGMlogo = "/images/globaJLinkerLogo.jpg";
    } elseif (isset($_SESSION["mycid"]) == 8){
        $storeTitle = "Jet Airways BrandSTORE";
        $storeDLogo = "/images/jetAirwaysLogo.jpg";
        $storeGDlogo = "/images/globaJLinkerLogo.jpg";
        $storeGMlogo = "/images/globaJLinkerLogo.jpg";
    }elseif (isset($_SESSION["mycid"]) == 9){
        $storeTitle = "Jet Airways BrandSTORE";
        $storeDLogo = "/images/jetAirwaysLogo.jpg";
        $storeGDlogo = "/images/globaJLinkerLogo.jpg";
        $storeGMlogo = "/images/globaJLinkerLogo.jpg";
    } elseif (isset($_SESSION["mycid"]) == 10){
        $storeTitle = "Jet Airways BrandSTORE";
        $storeDLogo = "/images/jetAirwaysLogo.jpg";
        $storeGDlogo = "/images/globaJLinkerLogo.jpg";
        $storeGMlogo = "/images/globaJLinkerLogo.jpg";
    } else{
       $storeDLogo = "/images/jetAirwaysLogo.jpg";
       $storeGDlogo = "/images/globaJLinkerLogo.jpg";
       $storeGMlogo = "/images/globaJLinkerLogo.jpg";
    }
?>

2 Answers 2

1

You condition is incorrect, use conjunction:

if(isset($_SESSION["mycid"]) && $_SESSION["mycid"] == "14")
...
elseif(isset($_SESSION["mycid"]) && $_SESSION["mycid"] == "8")

More efficient would be to check isset in the outer if only once and then check values:

if(isset($_SESSION["mycid"]))
{
        if($_SESSION["mycid"] == "14")
        {
             ...    
        }
        elseif($_SESSION["mycid"] == "8")
        {
             ...
        }
        else
        {
             ...
        }
}
else
{
       //action for $_SESSION["mycid"] not set
}
Sign up to request clarification or add additional context in comments.

Comments

0

try this,

if (isset($_SESSION["mycid"])) {
    switch ($_SESSION["mycid"]) {
        case 7:
            $storeTitle = "Jet Airways BrandSTORE";
            $storeDLogo = "/images/jetAirwaysLogo.jpg";
            $storecolor1 = "#000"; //applied in header background
            $storecolor2 = "#FF9304"; //applied in mini header background 
            $storeGDlogo = "/images/globaJLinkerLogo.jpg";
            $storeGMlogo = "/images/globaJLinkerLogo.jpg";
            break;
        case 8:
            $storeTitle = "Jet Airways BrandSTORE";
            $storeDLogo = "/images/jetAirwaysLogo.jpg";
            $storeGDlogo = "/images/globaJLinkerLogo.jpg";
            $storeGMlogo = "/images/globaJLinkerLogo.jpg";
            break;
        case 9:
            $storeTitle = "Jet Airways BrandSTORE";
            $storeDLogo = "/images/jetAirwaysLogo.jpg";
            $storeGDlogo = "/images/globaJLinkerLogo.jpg";
            $storeGMlogo = "/images/globaJLinkerLogo.jpg";
            break;
        case 10:
            $storeTitle = "Jet Airways BrandSTORE";
            $storeDLogo = "/images/jetAirwaysLogo.jpg";
            $storeGDlogo = "/images/globaJLinkerLogo.jpg";
            $storeGMlogo = "/images/globaJLinkerLogo.jpg";
            break;
        case 14:
            $storeTitle = "Federation of Indian Exports Organization BrandSTORE";
            $storeDLogo = "/images/hid/figo-14.jpg";
            $storecolor1 = "#02ADF2"; //applied in header background
            $storecolor2 = "#FF9304"; //applied in mini header background 
            $storeGDlogo = "/images/hid/gl-14.jpg";
            $storeGMlogo = "/images/hid/gl-m-14.jpg";
            break;
    }
} else {
    $storeDLogo = "/images/jetAirwaysLogo.jpg";
    $storeGDlogo = "/images/globaJLinkerLogo.jpg";
    $storeGMlogo = "/images/globaJLinkerLogo.jpg";
}

Here, Dont forget to pass default values, which variables are not set due to condition

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.