if (!$currentUser->get('id')) { // The current user's session has expired or they are not authenticated. CRM_Core_Error::displaySessionError(); }
if (!CRM_Core_Permission::check('access CiviCRM')) { // The user does not have permission to access CiviCRM. CRM_Core_Error::displaySessionError(ts('You do not have permission to access this page.')); }In this example, we check whether the current user has permission to access CiviCRM. If they do not, we call CRM_Core_Error::displaySessionError to display a custom error message to the user. As mentioned earlier, CRM_Core_Error::displaySessionError is a function in the CiviCRM package, which is a library of open-source software designed for nonprofit organizations and other civic groups.