PHP管理IF Else条件

我有一个网站,其中根据查询字符串解析到URL的方式创建了会话。我正在读取会话值,因此想要更改网站的标题。事情可以在下面的代码下正常运行,但不会进入elseif条件。如果我尝试打印会话值,它会给我正确的回声,但条件不能正常工作。它可以与If和else一起使用,但不能进入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";

    } 



守着星空守着你
浏览 151回答 2
2回答

偶然的你

您的条件不正确,请结合使用:if(isset($_SESSION["mycid"]) && $_SESSION["mycid"] == "14")...elseif(isset($_SESSION["mycid"]) && $_SESSION["mycid"] == "8")效率更高的方法是if只在外部检查一次isset ,然后检查值:if(isset($_SESSION["mycid"])){&nbsp; &nbsp; &nbsp; &nbsp; if($_SESSION["mycid"] == "14")&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;...&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; elseif($_SESSION["mycid"] == "8")&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;...&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; else&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;...&nbsp; &nbsp; &nbsp; &nbsp; }}else{&nbsp; &nbsp; &nbsp; &nbsp;//action for $_SESSION["mycid"] not set}

忽然笑

试试这个,if (isset($_SESSION["mycid"])) {&nbsp; &nbsp; switch ($_SESSION["mycid"]) {&nbsp; &nbsp; &nbsp; &nbsp; case 7:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $storeTitle = "Jet Airways BrandSTORE";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $storeDLogo = "/images/jetAirwaysLogo.jpg";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $storecolor1 = "#000"; //applied in header background&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $storecolor2 = "#FF9304"; //applied in mini header background&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $storeGDlogo = "/images/globaJLinkerLogo.jpg";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $storeGMlogo = "/images/globaJLinkerLogo.jpg";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; case 8:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $storeTitle = "Jet Airways BrandSTORE";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $storeDLogo = "/images/jetAirwaysLogo.jpg";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $storeGDlogo = "/images/globaJLinkerLogo.jpg";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $storeGMlogo = "/images/globaJLinkerLogo.jpg";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; case 9:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $storeTitle = "Jet Airways BrandSTORE";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $storeDLogo = "/images/jetAirwaysLogo.jpg";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $storeGDlogo = "/images/globaJLinkerLogo.jpg";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $storeGMlogo = "/images/globaJLinkerLogo.jpg";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; case 10:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $storeTitle = "Jet Airways BrandSTORE";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $storeDLogo = "/images/jetAirwaysLogo.jpg";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $storeGDlogo = "/images/globaJLinkerLogo.jpg";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $storeGMlogo = "/images/globaJLinkerLogo.jpg";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; case 14:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $storeTitle = "Federation of Indian Exports Organization BrandSTORE";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $storeDLogo = "/images/hid/figo-14.jpg";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $storecolor1 = "#02ADF2"; //applied in header background&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $storecolor2 = "#FF9304"; //applied in mini header background&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $storeGDlogo = "/images/hid/gl-14.jpg";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $storeGMlogo = "/images/hid/gl-m-14.jpg";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; }} else {&nbsp; &nbsp; $storeDLogo = "/images/jetAirwaysLogo.jpg";&nbsp; &nbsp; $storeGDlogo = "/images/globaJLinkerLogo.jpg";&nbsp; &nbsp; $storeGMlogo = "/images/globaJLinkerLogo.jpg";}在这里,不要忘记通过default values,variables由于未设置condition
打开App,查看更多内容
随时随地看视频慕课网APP