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

前端 未结 9 1483
无人及你
无人及你 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:08

    You tried on this Iva. Below is the code that works:

    $url != 'your-url-which-you-do-not-what-direct access';
    
    if ($_SERVER['HTTP_REFERER'] == $url) {
      header('Location: otherurl.php'); //redirect to some other page
      exit();
    }
    

    Ensure this appears at the top of the page where you do not want direct access to.

提交回复
热议问题