peterlozano.com

Personal blog of Pedro Lozano (PHP/Drupal Developer)



Posted by Pedro Lozano

A little trick I started using recently: using cookies to alter Drupal behavior when navigating the site (usually developing or debugging) with a shared user account that should present a different behavior to the rest of the people.

Use case. A few developers may be building a site and they all use the admin account for setup tasks. Now one of them doesn't want to see url aliases because he needs to see node ids in urls for debugging purposes.

You could put a code like this in settings.php:

function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
  if ($_COOKIE['disable_url_aliases']) {
    $path = $original_path;
  }
}

Now, using a Firefox extension like Firecookie or Web Developer, you can add a cookie called disable_url_aliases in your browser that will disable url aliases only for you, the rest of the developers won't notice.

Other use case is using a different theme.

/**
 * Implementation of hook_init().
 */
function project_customizations_init() {
  global $custom_theme;
 
  if ($_COOKIE['custom_theme']) {
    $custom_theme = $_COOKIE['custom_theme'];
  } 
}

For this snippet to work you must create the cookie custom_theme with the value set to the name of the theme that you want to use.

Other case ideas:

  • Displaying debug information when navigating as anonymous.
  • Avoid analytics when when navigating as anonymous.
  • Navigate with a different language.
  • Disable cache. Combined with xdebug profiler it allows you to profile anonymous page generation while still keep the cache active for the rest of the users.

I'm sure this list can be made longer. You are welcome to post your ideas in the comments.

First post

07 Nov 2009
Posted by Pedro Lozano

This is just a first testing post so I can start building some views for the site. More soon...



Flickr


twitter

  • I just successfully compiled Drupal 6 using hiphop-php with no modifications but it doesn't seem to run. 2 weeks 1 day ago
  • Exciting day for performance engineers, Facebook releases HipHop, PHP to C++ translator. http://bit.ly/allDwj 4 weeks 6 days ago
  • iPad Nano http://bit.ly/d1aGdX 5 weeks 4 days ago

Follow peterlozano on Twitter



Site License

Creative Commons Attribution 3.0 Unported
This interactive resource, peterlozano.com, by Pedro Lozano is licensed under a Creative Commons Attribution 3.0 Unported license.