开发者

PHP if statement with isset not working

开发者 https://www.devze.com 2023-02-13 07:51 出处:网络
I presumed this was easy code but this doesnt work as intended: $id = $_GET[\'id\']; if (!isset($id)){ header(\"HTTP/1.1 404 not found\");

I presumed this was easy code but this doesnt work as intended:

$id = $_GET['id'];
if (!isset($id)){
    header("HTTP/1.1 404 not found");
    include("404.php");
开发者_StackOverflow社区}
else {
    include('includes/functions.php'); 
}

So i've taken the get parameters off of the URL yet i dont receive a 404 error?

Any ideas?


You must do the test on $_GET['id'] directly:

if(!isset($_GET['id']) { ... }

Even if $_GET['id'] isn't set, since you tried to assign it to $id, $id starts to exist, so the test returns true and thus you don't have a 404 error.


You are checking if $id is set. And it is :

$id = $_GET['id'];

So you must check if the get variable is set:

isset($_GET['id'])


you have created $id variable in first line. You should check $_GET['id']. Also you can check this variable for empty.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号