I am a relative newbie looking for guidance on how to best tackle a requirement within the Drupal 7 realm. I have an entity defined with a field containing the URL for an external resource and would like to be able to manipulate the URL string programmatically before rendering the field as a hypertext link within a view. I thought about storing the alternate URLs in the database but the format is subject to change so the dynamic approach is more attractive since it would only involve a single edit. I need to first check the $_SERVER['REMOTE_ADDR'] to determine whether or not to execute this code because if the user is requesting the resource from a location off site then a proxy link must be generated for licensing purposes. What approach would make the most sense for this use case?


Store the data in the cleanest way possible and then use something like Custom Formatters or a custom module to modify the presentation of the stored data.

As for using $_SERVER['REMOTE_ADDR'] I feel that I need more data on how and where this will be used. Have you considered using the permissions or roles built into Drupal?

You would likely need to place this in a preprocess function to conditionally call it for a specific IP address.

For example.

 * Implements hook_preprocess_node().
function hook_preprocess_node(&$variables) {
    //Obviously a real IP is required above for correct syntax.
    if ($_SERVER['REMOTE_ADDR'] == xxx.xxx.xxx.xxx) {
        //Next you can edit the output of any field you want if your remote address matches.
        $variables['field_myfield'][LANGUAGE_NONE][0]['value'] = 'Something Modified Here';
  • edited question to clarify the usage of $_SERVER['REMOTE_ADDR'] – WuWei Jun 28 '12 at 20:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.