Skip to content
PHP Logo

How can the text displayed in the authentication prompt be customized when using htaccess or WWW-Authenticate in PHP?

When using htaccess or WWW-Authenticate in PHP for authentication, the text displayed in the authentication prompt can be customized by setting the realm parameter in the header. This parameter specifies the realm name that will be displayed in the authentication prompt. By setting the realm to a specific value, you can provide a more descriptive message to the user.

php
<?php
header('WWW-Authenticate: Basic realm="Custom Realm Name"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required';
exit;
?>