I have set up a basic authentication on one section of my website as documented here, it works fine, but now I need to be able to access the user name in order to filter certain results. But $_SERVER['PHP_AUTH_USER'] wont work. Is there any other way to see who is logged in?
My .htaccess file:
AuthType Basic
AuthName "You need to login to access this page."
AuthUserFile /usr/local/..../.htpasswd
Require valid-user
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
It is marked as duplicate, but I don't see where is the answer to my problem? Can someone help please? Admin?
$_SERVERis designed for server related info (paths, uri etc.) whereas$_SESSIONis designed for things related to the users current session (username, breadcrumbs, auth token maybe?). Just make sure tosession_start()before that :Pvar_dump($_SERVER);and see if you can find the username somewhere in the output. Depending on how specifically PHP is embedded into the web server, you might find this info in slightly different fields. Also, read what php.net/manual/en/features.http-auth.php has to say about when HTTP Auth is triggered from “outside” PHP, on the web server level.$_SERVER['PHP_AUTH_USER']wont work"? Is the field blank?