preventing direct access to a php page, only access if redirected

前端 未结 9 1356
无人及你
无人及你 2021-01-05 11:30

I want to make my php page only accessible from another page redirect and prevent my user from accessing it directly.

I mean, let\'s say I have a page called

9条回答
  •  太阳男子
    2021-01-05 12:09

    You can use $_SERVER["HTTP_REFERER"]. Put the following code in the beginning of your php file and set $url to be equal of your desired url for example http://a.com/main.php

    if ($_SERVER['HTTP_REFERER'] != $url) {
        header('Location: noaccess.php');
        exit();
    }
    

提交回复
热议问题