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