Skip to content

Instantly share code, notes, and snippets.

@perusio
Created December 27, 2011 07:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save perusio/1522957 to your computer and use it in GitHub Desktop.
Save perusio/1522957 to your computer and use it in GitHub Desktop.
Simple module to add a header with the user ID
<?php
/**
* @file drupal_uid_header.module
* @author António P. P. Almeida <appa@perusio.net>
* @date Tue Dec 27 2011
*
* @brief Sets an HTTP header with the UID (Drupal 6).
*
*/
/**
* Implements hook_init().
*/
function drupal_uid_header_init() {
global $user;
if ($user->uid > 0) {
$h = header_list();
$k = array_search('X-Drupal-UID', $h);
// Check to see if the the current user is valid, i.e., not tampered with.
if ($k) {
$current_uid_header_array = explode(' ', $h[$k]);
}
// If invalid or not set then send the header with the correct UID.
if (!$k || $current_uid_header_array[1] != $user->uid) {
drupal_add_http_header('X-Drupal-UID', filter_var($user->uid, FILTER_SANITIZE_NUMBER_INT));
}
}
} // drupal_uid_header_init
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment