Cookie Domain in Drupal

There are times when we need to force a specific cookie domain in Drupal. This often comes as a request from the Analytics team as the Google Analytics module uses the $cookie_domain variable in its tracking.

This variable is set in settings.php. Care has to be taken though because setting the cookie domain to be that of the live site will prevent you from logging in on a dev site.
Here is the fix:
Add this line to settings.php

<?php
$cookie_domain
= (strstr($_SERVER['SERVER_NAME'], 'mydevserver.com') ? '' : '.myliveserver.com');
?>

The live domain (the false option in the ternary) MUST start with a dot.

section: