PHP - Display a 404 Error without redirecting to another page

后端 未结 6 1558
天涯浪人
天涯浪人 2020-12-05 05:38

I want to display a 404 Error if a user reaches a page that exists but I don\'t want him/her to see.

I don\'t want to do redirect (that would cause the address bar t

6条回答
  •  不知归路
    2020-12-05 06:23

    What you write makes it hard to us to understand.

    I want to redirect any incoming user to the 404 Error Page if s/he reaches the page I don't want him/her to reach.

    So, a person reaches a page that exists?

    If the person reaches for example a protected page that he/she is not supposted to see. Using header is the best way. Your options are to echo meta-refresh or javascript, but header is much cleaner. You could display something like You do not have permission to do that! which is pretty common on the web. If you don't want to redirect you could display a 404 "fake message" via the header.

    If you are talking about someone reaching a 404 page, a file that does not exists, you only option is to use .htaccess

提交回复
热议问题