简体   繁体   中英

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 :

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. Anyone can help?

My shot - isset determine if a variable is set and is not NULL. So if your url contains just ?ref (not ?ref=subpage ) the condition is met, however you will be redirected to header("Location: /" . NULL); .

Try using !empty() instead of isset() .

BTW: Always add exit after header("Location: ...")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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