0

我的基于用户的网站设置如下:

  1. 每个用户在 mydomain.com/user123 上都有自己的个人资料页面
  2. 在幕后,用户不知道,这重定向到 mydomain.com/profile.php?user=user123

如果有人访问任何 URL,如 mydomain.com/randomstring,我如何确保查看器在“randomstring”不等于当前用户名的情况下看不到“mydomain.com/profile.php?user=randomstring”在我的网站上注册,但他们看到的是 404 错误?

(出于参考目的,profile.php 填充了一个预定义的模板,该模板提取与每个唯一用户名关联的自定义变量。因此,如果某个用户名不存在,则转到 mydomain.com/randomstring 会显示一个名为“ randomstring 的个人资料页面。”)

4

2 回答 2

2
<?php
if(/*USER_DOESN'T_EXIST*/)
header("HTTP/1.0 404 Not Found");
?>
于 2012-10-09T18:43:27.430 回答
0
   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");

或者

让 apache 为你处理

在您的 htaccess 文件中

ErrorDocument 404 /missing.html

或在您的 php 脚本中

header("HTTP/1.0 404 Not Found");
于 2012-10-09T19:07:33.683 回答