How can one allow non-registered users to browse member profiles and directories in a PHP community script without requiring login?

To allow non-registered users to browse member profiles and directories in a PHP community script without requiring login, you can create a conditional statement that checks if the user is logged in or not. If the user is not logged in, you can still display the profiles and directories. However, you may need to limit the information displayed to non-registered users for privacy reasons.

<?php
// Check if the user is logged in
if(isset($_SESSION['user_id'])) {
    // User is logged in, display profiles and directories
    // Add your code to display member profiles and directories here
} else {
    // User is not logged in, display a message or redirect to login page
    echo "Please login to access member profiles and directories.";
    // Alternatively, you can redirect non-logged in users to the login page
    // header("Location: login.php");
}
?>