Is there a way to set Cookie domain?

For Joomla! 1.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Locked
radopod
Joomla! Intern
Joomla! Intern
Posts: 60
Joined: Sun Jun 17, 2007 7:16 am

Is there a way to set Cookie domain?

Post by radopod » Fri Mar 06, 2009 7:39 pm

Hey all
I have been looking for a way to achieve this for a few weeks now but have found nothing. Finally I decided to bother you guys. ;) So is it possible to set the Cookie domain in Joomla!?

I need this so that we can get the JFusion Component of ours to bridge multiple Joomla! installations in such a way that dual login works across sub domains on a single domain.

Looking forward to a reply soon.

Thanks in advance.
Project Manager
http://jfusion.org - Universal User Integration

User avatar
Robin
Joomla! Master
Joomla! Master
Posts: 15745
Joined: Thu Aug 18, 2005 10:41 am

Re: Is there a way to set Cookie domain?

Post by Robin » Fri Mar 06, 2009 7:42 pm

Moderator note; moving to correct forum

radopod
Joomla! Intern
Joomla! Intern
Posts: 60
Joined: Sun Jun 17, 2007 7:16 am

Re: Is there a way to set Cookie domain?

Post by radopod » Fri Mar 06, 2009 7:51 pm

Thanks a lot for moving it to the right forum.
Project Manager
http://jfusion.org - Universal User Integration

User avatar
ianmac
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 4784
Joined: Sat Sep 24, 2005 11:01 pm
Location: Toronto, Canada

Re: Is there a way to set Cookie domain?

Post by ianmac » Sat Mar 07, 2009 1:25 am

radopod wrote:Thanks a lot for moving it to the right forum.
I'm not certain, but I doubt that this will work because this is a browser security issue.

It generally isn't good to be able to set cookies on other site's domains.

Ian

recraig2
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Wed Mar 11, 2009 12:20 pm
Contact:

Re: Is there a way to set Cookie domain?

Post by recraig2 » Tue Mar 24, 2009 8:38 pm

No it doesn't work, because of Ian's point. You must install under the same domain.

thehulaqueen
Joomla! Apprentice
Joomla! Apprentice
Posts: 28
Joined: Tue Mar 25, 2008 3:10 pm

Re: Is there a way to set Cookie domain?

Post by thehulaqueen » Thu Jun 25, 2009 11:22 pm

it's not about setting a cookie to a different domain... but having control as to whether or not you use www.mydomain.com or .mydomain.com

We're bridging PHPBB and Joomla/Virtuemart, and having great difficulty, because of not being able to clearly show the format cookies need to be in. Virtuemart seems to set some with www and others without... which is doubly confusing.

This is discussed:
http://joomlacode.org/gf/project/joomla ... m_id=16939
http://groups.google.com/group/joomla-d ... raot&pli=1
http://www.joomlashack.com/joomla-how-t ... n-mismatch

In case anyone else wants to see the best progress of this I've seen so far.. there is a hack that exists to be able to set the cookie domain for Joomla, and hopefully will make the next version!!

mihajlovski
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Fri Jun 26, 2009 10:36 pm
Location: Macedonia

Re: Is there a way to set Cookie domain?

Post by mihajlovski » Fri Jun 26, 2009 10:48 pm

Hi! I posted this solution in the JFusion forums; I am posting it here as well. I hope it helps. ;)

To fix the login issue, two problems need to be solved: setting cookies and opening sessions. We need to tell Joomla to always use our top domain (and not subdomains) for these operations.

Be sure to replace mysite.com with your actual domain name below.

Fix Sessions:

File to edit:
\libraries\joomla\session\session.php

Find the two occurences of the line:

Code: Select all

session_start();
Add the following code on a new line right before session_start() is invoked:

Code: Select all

ini_set('session.cookie_domain','.mysite.com');
Fix Cookies:

Files to edit:
/libraries/joomla/application/application.php
/libraries/joomla/session/session.php
/plugins/system/remember.php

Find all the occurences of the setcookie(...) function in the files above.

Add an additional (domain) parameter: '.mysite.com'

Examples:

Code: Select all

setcookie(session_name(), '', time()-42000, '/');
transforms into

Code: Select all

setcookie(session_name(), '', time()-42000, '/', '.mysite.com');

Code: Select all

setcookie( JUtility::getHash('JLOGIN_REMEMBER'), false, time() - 86400, '/' );
transforms into

Code: Select all

setcookie( JUtility::getHash('JLOGIN_REMEMBER'), false, time() - 86400, '/', '.mysite.com' );
I am aware that this is not the most elegant solution, but it gets the job done. I hope this will help many site owners use the wonderful JFusion extension. Thanks to the JFusion team for bringing us this wonderful piece of software.

Greetings from Macedonia.
Forum signature rules: viewtopic.php?f=8&t=65

recraig2
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Wed Mar 11, 2009 12:20 pm
Contact:

Re: Is there a way to set Cookie domain?

Post by recraig2 » Wed Jul 01, 2009 4:37 pm

Mihajlovski! Thanks a ton! I'm trying this solution right now. I hadn't yet gotten JFusion to work properly and gave up completely on my Joomla site. This shows what effects on Joomla's useability and our preference to stick with it that an incompletely programmed extension can cause. I hope this works. Keep your fingers crossed, say a prayer.

00mike
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Mon Oct 27, 2008 3:05 pm

Re: Is there a way to set Cookie domain?

Post by 00mike » Thu Apr 01, 2010 3:57 pm

thanks mihajlovski you're a legend :)

Still, its kind of annoying that you need to edit all these core files to do something so simple. Surely it must be a common thing to want to share cookies between mysite.com and www.mysite.com? Would be good to have some config option in Joomla for this.

User avatar
hefesto
Joomla! Hero
Joomla! Hero
Posts: 2578
Joined: Fri Jan 20, 2006 12:37 am
Location: Seville - Spain
Contact:

Re: Is there a way to set Cookie domain?

Post by hefesto » Tue Apr 27, 2010 4:00 pm

Instead of hacking the core, wouldn't it be easier redirecting non www domain to www domain (or vice versa) using htaccess?
Spanish forum local moderator
Twitter: @isidrobaq
Comunidad Joomla de España: https://joomlaes.org
NO atiendo peticiones privadas de soporte. Por favor, pregunta en los foros.

gsinkaos
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Fri Oct 01, 2010 4:17 pm

Re: Is there a way to set Cookie domain?

Post by gsinkaos » Tue Nov 23, 2010 5:27 am

How would you go about setting up a cookieless subdomain. Ex. I have ping.com and i want to serve my images from assets.ping.com and make that a cookieless domain.

Or would I have to exclusively define www.ping.com as my cookie domain?

Any ideas?

jawilliams
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Fri Aug 01, 2008 2:37 am

Re: Is there a way to set Cookie domain?

Post by jawilliams » Tue Dec 28, 2010 6:07 pm

mihajlovski wrote:Hi! I posted this solution in the JFusion forums; I am posting it here as well. I hope it helps. ;)

To fix the login issue, two problems need to be solved: setting cookies and opening sessions. We need to tell Joomla to always use our top domain (and not subdomains) for these operations.

Be sure to replace mysite.com with your actual domain name below.

Fix Sessions:

File to edit:
\libraries\joomla\session\session.php

Find the two occurences of the line:

Code: Select all

session_start();
Add the following code on a new line right before session_start() is invoked:

Code: Select all

ini_set('session.cookie_domain','.mysite.com');
Fix Cookies:

Files to edit:
/libraries/joomla/application/application.php
/libraries/joomla/session/session.php
/plugins/system/remember.php

Find all the occurences of the setcookie(...) function in the files above.

Add an additional (domain) parameter: '.mysite.com'

Examples:

Code: Select all

setcookie(session_name(), '', time()-42000, '/');
transforms into

Code: Select all

setcookie(session_name(), '', time()-42000, '/', '.mysite.com');

Code: Select all

setcookie( JUtility::getHash('JLOGIN_REMEMBER'), false, time() - 86400, '/' );
transforms into

Code: Select all

setcookie( JUtility::getHash('JLOGIN_REMEMBER'), false, time() - 86400, '/', '.mysite.com' );
I am aware that this is not the most elegant solution, but it gets the job done. I hope this will help many site owners use the wonderful JFusion extension. Thanks to the JFusion team for bringing us this wonderful piece of software.

Greetings from Macedonia.
This does not work in J! 1.5.22, what version was this tried on. It caused my login to authenticate but not actually show logged in on the user side (backend showed login or multiple if retried). Do not attempt to use http://joomlacode.org/gf/project/joomla ... m_id=19948 either since that does the samething but implements a config variable in the configuration.php to turn it on or off (did the same as above code). I know in J! 1.6 they are playing with the same thing, but since not a full release not going to upgrade to it yet.

After trying both I did clear all cache and cookies and even reopened the browser with the same issue.


Locked

Return to “Joomla! 1.5 Coding”