-1

I have a page that I don't want users to access directly for security reasons.

For example I have a page profile.php; I want when a user presses the button the profile page will open and if he wants to access page directly from url it will restrict him.

<?php define('SECURE_PAGE', true);include 'includes/page.php';?>

I have tried this but couldn't solve my issue

mplungjan
  • 169,008
  • 28
  • 173
  • 236

1 Answers1

0

You can simply return 403 status code under certain condition:

if ($something) {
    http_response_code(403);
    // optionally display nice 403 page with `include()` or just `echo`.
    exit;
}
Robo Robok
  • 21,132
  • 17
  • 68
  • 126