Can the "define" function be used to protect pages in PHP? If so, how?

To protect pages in PHP, you can use the "define" function to define a constant that acts as a flag to check if a user is authorized to access the page. You can then use this constant in your code to restrict access to certain pages based on the user's authorization level.

define('AUTHORIZED', true);

if(!defined('AUTHORIZED')) {
    // Redirect or display an error message
    header("Location: unauthorized.php");
    exit();
}

// Your protected page content here