Johan Larsson
Johan Larsson

Reputation: 175

Send header 404 if id != $_get['id']

SQL query like this,

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

How to print a 404 header if the id != value of $_GET['id']?

Upvotes: 0

Views: 224

Answers (2)

Steve Robbins
Steve Robbins

Reputation: 13812

$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");

Also note, you should move away from deprecated mysql_* functions.

Also also note, Bobby Tables.

Upvotes: 4

mash
mash

Reputation: 15229

Not really sure which id you refer to, but you are looking for something along the lines of:

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

Upvotes: 1

Related Questions