Mike
Mike

Reputation: 119

404 error with user pages

I have my user-based site set up as follows:

  1. Each user has their own profile page at mydomain.com/user123
  2. Behind the scenes, and unbeknownst to the user, this redirects to mydomain.com/profile.php?user=user123

If someone visits any URL like mydomain.com/randomstring, how would I ensure that the viewer does not see "mydomain.com/profile.php?user=randomstring" in instances where "randomstring" is not equal to a current username that is registered with my site, but instead they see a 404 error?

(for reference purposes, profile.php populates a pre-defined template that pulls custom variables associated with each unique username. Therefore, if a certain username doesn't exist, going to mydomain.com/randomstring would bring up an empty page titled "randomstring's profile page.")

Upvotes: 0

Views: 118

Answers (2)

Arun Killu
Arun Killu

Reputation: 14243

   check the random string with database userid 
(i suppose the id is the user id) if user id not in db 
    header("location:404.php");

or

let apache handle for u

in your htaccess file

ErrorDocument 404 /missing.html

or in your php script

header("HTTP/1.0 404 Not Found");

Upvotes: 0

Lior
Lior

Reputation: 6051

<?php
if(/*USER_DOESN'T_EXIST*/)
header("HTTP/1.0 404 Not Found");
?>

Upvotes: 2

Related Questions