Forum Moderators: open

Message Too Old, No Replies

Cookie Trouble

Trouble with "www.mysite.com" and "mysite.com"...

         

kidd

1:39 pm on Apr 7, 2003 (gmt 0)

10+ Year Member



Hello:

I hope someone can help me put with a bit a problem I have hanging around.

Let me explain how it all happened...

  • The Start: My client has a suscription driven site and he wants to know how his suscribers find his site. So he asked me to come out with the best solution.

  • Solution: Since the tracking device has to be set to every page(at least the ones that are indexed in the robots), which are a lot since the site is a big one, I decided that the best to go was with [u]javascript[/u].

  • Creation: By giving a solution now I had to create it and test it. I created a ".js" file, made some test pages and statrted the testing.

  • Testing: I made a lot of testings since I only want the cookie to capture the FIRST arrival and not each. It worked well, I was able to capture the referrer and the retrieve it. But when I made my final test, I found a problem.

  • The Problem: I thought that all was going great and I should be by bed in no time, but I found a "bug" in my code. The problem is that when you access the site via "www.mysite.com" it retrieves and writes a different cookie when you are in "mysite.com". Since I never really worked with cookies I didn't know how to solve this.

I made a lot of searches trough the net trying to find the solution, but, without success. I hope someone can help me out on this, on how to make and retrive the same cookie no matter if you are in "www.mysite.com" or "mysite.com".

All help is very appreciated...

THANKS

jdMorgan

2:14 pm on Apr 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



kidd,

AFAIK, you can't change the cookie-handling of client browsers. This is for security reasons.

The simplest solution (IMHO) is to not allow the use of multiple domain names. Instead, detect accesses to any secondary domain names, and 301-redirect them to your primary domain. Using this technique, no cookie can be set in the wrong domain. It also has the added benefit of reducing the number of incoming links to secondary doamins, concentrating link popularity and Google PageRank into the primary domain.

You can do this using client- or server-side scripting, or implement it at the server level, which is much more efficient.

Jim

bird

10:55 pm on Apr 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As far as I understand the RFCs, a cookie set for "example.com" should also be returned to "www.example.com" and "somethingelse.example.com". So you could try to use the short form in all cookies, and run a few experiments to see what the different browsers do with that. The actual behaviour in such a situation may depend on their security settings.

Of course, redirecting to one primary name as jdMorgan suggests is also a good idea, for this and a number of other reasons.