Inspect the referrer in PHP

前端 未结 4 1047
星月不相逢
星月不相逢 2020-12-06 00:44

Is it possible to check who is entering your website in PHP. I have a web application ( written in PHP) that should only allow users entering from some particular websites.

4条回答
  •  清歌不尽
    2020-12-06 01:17

    While you can look at $_SERVER['HTTP_REFERER'] to get the referring site, don't bet the farm on it. The browser sets this header and it's easily spoofed.

    If it's critical that only people coming from specific referrers view your site, don't use this method. You'll have to find another way, like basic auth, to protect your content. I'm not saying that you shouldn't use this technique, just keep in mind that it's not fool-proof.

    BTW, you can also block referrers at the apache level using mod_rewrite.

提交回复
热议问题