php - 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";
} else{
$storeDLogo = "/images/jetAirwaysLogo.jpg";
$storeGDlogo = "/images/globaJLinkerLogo.jpg";
$storeGMlogo = "/images/globaJLinkerLogo.jpg";
}
?>
解决方案
您的条件不正确,请使用连词:
if(isset($_SESSION["mycid"]) && $_SESSION["mycid"] == "14")
...
elseif(isset($_SESSION["mycid"]) && $_SESSION["mycid"] == "8")
更有效的方法是只在外部if
检查一次 isset,然后检查值:
if(isset($_SESSION["mycid"]))
{
if($_SESSION["mycid"] == "14")
{
...
}
elseif($_SESSION["mycid"] == "8")
{
...
}
else
{
...
}
}
else
{
//action for $_SESSION["mycid"] not set
}
推荐阅读
- android - 如何在Android中修复滚动视图下方的底部导航栏?
- java - 在运行时创建 List<> 并在 java 中添加值的动态方法
- django - 自动在 RichTextField 中查找标签名称并将它们链接到现有标签
- json - 将 800 个 json 文件发布到 Shopify API(限制为 40/秒)
- qt - 如何在另一个应用程序中使用 QT QML C++ 插件?
- python - 获取 < > 之间的字符串列表
- python - 如何使用 line.split() 将文本文件拆分为不同的列
- javascript - 将用户列表发送到我的 Messenger 页面并使用 ChatApp.vue 组件在页面 (messenger.blade.php) 中显示它们
- java - 无法在表之间建立连接 正在读取但不能插入
- javascript - 故事书构建每次都失败