简体   繁体   English

在开关盒内使用插头位置

[英]using header location inside switch case

I have 我有

$CID = $_REQUEST ['cid'];
$UID = $_REQUEST ['uid'];

if ($UID == '0') {
    header ( 'Location: url/you-need-to-log-in-before-redirect/' );
} else {

    switch ($CID) {
        // go to URL1 case number is the same as CID
        case "147" :
            header ( 'Location:  url' . $UID );
            break;
        case "148" :
            header ( 'Location: url' . $UID );
            break;
        default :
            echo "Something went terribly wrong";
    }
}

Is this ok? 这个可以吗? I have a problem of $UID registering as blank which should not be possible as it is always set to be 0 for non-registered users and for registered it's unique. 我有一个$ UID注册为空白的问题,这应该是不可能的,因为对于未注册的用户,始终将其设置为0,对于已注册的用户,它是唯一的。 should i use exit() instead of break? 我应该使用exit()而不是break吗? or both? 或两者? Or should i not be using header loaction at all to send users forward...i have hundreds of cases inside this switch case statement. 还是我根本不应该使用标头位置来转发用户...我在此switch case语句中有数百种情况。 i cant post any actual urls so the 'url' in example is not a variable but just a placeholder for the actuall full address. 我无法发布任何实际的网址,因此示例中的“网址”不是变量,而只是实际完整地址的占位符。

Is the zero's type integer? 零的类型是整数吗? If yes your condition is wrong, because it tests for string but you have an integer. 如果是,则您的条件是错误的,因为它会测试字符串,但是您有一个整数。

Try: if ($UID == 0) { and the same for the switch cases. 尝试: if ($UID == 0) {并且对于切换情况相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM