Created
December 27, 2011 07:31
-
-
Save perusio/1522957 to your computer and use it in GitHub Desktop.
Simple module to add a header with the user ID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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