Does anyone know how to set cookie_domain to use an IP-Address and not a domain name?

I recently put together a SSO solution between Drupal and Moodle. Drupal is acting as the users repository with Moodle as a subdirectory.

To get the sso working I'm using the moodle-sso module to good effect.

The only problem is that logging out of moodle does not log a user out of drupal.

After much googling, I found articles indicating cookies are the key to solving this problem.

I attempted following moodle-sso cookie_domain instructions but then I can't log into my site anymore because I access my dev site via IP address and not a domain name.

I set cookie_domain as follows: $cookie_domain = '';

The project structure is

Any help is appreciated.


I added the following data to my /etc/hosts file on my Linode server: dev.drupalsite.com.

When I visit dev.drupalsite.com I receive the following error:


You don't have permission to access / on this server.

Clearly, dev.drupalsite.com is not a globally recognised URL but how do I use it to access my website on a LIVE Linode server?

1 Answer 1


$cookie_domain can only be set to a domain that you want the Set-Cookie header to specify. This doesn't include protocol or path, just the domain with a leading dot (e.g. ".example.com"). If you leave $cookie_domain commented out, the browser will default to the domain that you requested it on.

If you need to access a Drupal site by IP when its cookie is set to another domain, you can create a subdomain on your hosts file that maps to the IP. dev.example.com

Once that's saved to your hosts file, you should be able to browse to http://dev.example.com/ and have your web browser send the relevant cookies (assuming the cookies of domain are set to "example.com").

  • Hey Shawn, thank you so much. I added a quick update to my question.
    – sisko
    Sep 19, 2015 at 16:21
  • Hosts files map a domain to an IP address. You can't map a path in it. You still have to request the site in its subdir.
    – Shawn Conn
    Sep 19, 2015 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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