简体   繁体   English

php if(isset($ _ GET ['something']))无法正常工作

[英]The php if(isset($_GET['something'])) is not working

I tried my best to figure out how to redirect someone based on the index.php?ref=[link] , searched the internet... And couldn't figure out, here is my code : 我尽力找出如何基于index.php?ref=[link]重定向某人,在互联网上搜索...而且不知道,这是我的代码:

if(isset($_GET['ref'])){
    header("Location: /" . $_GET['ref']);
}else if(empty($_GET['ref'])){
    header('Location: /welcome/');
}else{
    header('Location: /welcome/');
}

It always executes the else if one, even if the value in ?ref is set. 即使设置了?ref的值,它也总是执行else if一个)。 Anyone can help? 有人可以帮忙吗?

My shot - isset determine if a variable is set and is not NULL. 我的镜头isset确定是否设置了变量并且不为NULL。 So if your url contains just ?ref (not ?ref=subpage ) the condition is met, however you will be redirected to header("Location: /" . NULL); 因此,如果您的网址仅包含?ref (不是?ref=subpage ),则满足条件,但是您将被重定向到header("Location: /" . NULL); .

Try using !empty() instead of isset() . 尝试使用!empty()而不是isset()

BTW: Always add exit after header("Location: ...") 顺便说一句:总是在header("Location: ...")之后添加exit

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

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