php - 如果 id != $_get ['id' 则发送 header 404]

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

像这样的SQL查询,

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

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

最佳答案

$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 .

关于php - 如果 id != $_get ['id' 则发送 header 404],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12046694/

相关文章:

mysql如何显示每个客户的最后2条记录

SQLDeveloper 更改大小写(破坏格式)

php - SQL 查询在 LEFT JOIN 后未返回预期结果(包括架构和图片)

PHP: Controller 中的 Symfony2 MySQL SELECT 查询

MySQL、json、JSON_ARRAY_APPEND - 为什么 append 在 5.7.13 上不起作用?

php - 如何在codeigniter中使用if条件、And条件和where条件编写选择查询

php - 使用 XAMPP : [PDOException] could not find driver 的 Laravel 迁移错误

php - jquery、json 和成功函数

mysql - 如何编写 MySQL 选择查询来获取选择列中的重复项,但在另一个列中获取唯一的

sql - 普通表表达式,遍历图时如何避免无限递归?