I wanting to create a custom Drupal response header to be returned on each pageview so it can be parsed on to a 3rd party application. Basically want I want to do is create a response header that returns the value of the logged in user. For example if I created a response header called "drupal-user" and a anonymous user was browsing the site the response header would look like;

drupal-user:anonymous

Likewise if a user called joeblogs was logged in the response header would look like this;

drupal-user:joeblogs

How can I do this?

Comments

mm167’s picture

try add the following:

global $user; 
if ($user->uid == 0) {
   $username = "anonymous";
} else {
   $username = $user->name;
}

header("drupal-user: $username");