-2

How to display 404 page when the user is not found.
Consider a website extracting username from $_GET variable like

example.com/users/?username=johndoe // Normal john doe's profile will be displayed

and

example.com/users/?username=jimmy //Should display 404 page without changing url

If a user is not found found in database.It should show a 404 page.

Thanks in Advance

2

2 Answers 2

0

Example:

header($_SERVER['SERVER_PROTOCOL']." 404 Not Found");
echo "Sorry, but user not found :("; //or include your 404 html file
die;
0

Check if user is in database, if not, you can include an error page.

$con = mysqli_connect("example.com", "user", "abc123", "db_name");
$result = mysqli_query($con,"SELECT * FROM user WHERE username = ".$_GET['username']);
if($result == false)
{
    require('error.php');
    exit();
}

// Contine displaying user page.

Make sure to check SQL injection!

Not the answer you're looking for? Browse other questions tagged or ask your own question.