如果id!= $ _get ['id']则发送标头404

时间:2012-08-20 23:42:21

标签: php mysql sql http-status-code-404

像这样的SQL查询,

$uid = $_GET['id'];
$result = mysql_query("SELECT name, lastname, email FROM users WHERE id = '$uid'");

如果$!_GET ['id']的id!=值,如何打印404标题?

2 个答案:

答案 0 :(得分:4)

$uid = mysql_real_escape_string($_GET['id']);
$result = mysql_query("SELECT name, lastname, email FROM users WHERE id = '{$uid}'");
if (!result || mysql_num_rows($result) == 0)
    header("Status: 404 Not Found");

另请注意,您应该放弃已弃用的mysql_*函数。

另请注意,Bobby Tables

答案 1 :(得分:1)

不确定您引用的id,但您正在寻找以下内容:

if (id != $_GET['id'])
    header("Status: 404 Not Found");