Reply
cookie problem www. and no www.
Old 04-10-2008, 09:29 AM cookie problem www. and no www.
Super Talker

Posts: 122
So I noticed the other night when messing on my website that if I'm logged in at http://mysite.com, then go to www.mysite.com, it's not logged in. And I assume this is because when the cookie is created, it's based on the URL location, and since the www is different without it, it doesn't recognize the cookie that is set when I add the www. Is there a simple fix for this?
kbfirebreather is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 04-10-2008, 10:17 AM Re: cookie problem www. and no www.
nyef's Avatar
Ultra Talker

Posts: 267
Name: Lucas
You are correct. mysite.com and www.mysite.com are different domains. Since one is a subdomain of the other it is possible to use one cookie for both (by designating authority for cross-site scripting to the parent mysite.com) HOWEVER: Having your site accessible under multiple domains (www and no www count as multiple domains) is VERY BAD for SEO as it can flag you in the search engines as having duplicate content.

Pick either www or no www, but don't do both. Have a redirect on whichever you DON'T do so that visitors that type in the alternate will still end up at your site.
nyef is offline
Reply With Quote
View Public Profile Visit nyef's homepage!
 
Old 04-10-2008, 10:50 AM Re: cookie problem www. and no www.
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 6,172
Name: Dan
Location: Swindon
not sure you actually answerd the question there nyef...

But what he said is true you should stick to one or the other i personally think the www. thing should be dropped full stop. its silly..

anwyay

When you set the cookie you should have .domain.tld NOT domain.tld this means it works for that domain plus subdomains (ie www.)

example:
PHP Code:
setcookie("TestCookie"$valuetime()+3600"/"".example.com"1); 
Rep points apprieciated

Dan
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is online now
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 04-11-2008, 03:19 AM Re: cookie problem www. and no www.
mtishetsky's Avatar
King Spam Talker

Posts: 1,054
Name: Mike
Location: Mataro, Spain
If a cookie is set for domain .example.com (with the dot in front) it would be passed by browser to example.com and all its subdomains. If a cookie is set for domain .www.example.com it will be passed only to this subdomian and all its fourth level subdomains (test.www.example.com, asdf.www.example.com) and so on. You should check your cookie setting logic and correct it accordingly.
__________________
Free Mobile Phone Themes

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 04-11-2008, 03:55 AM Re: cookie problem www. and no www.
BamaStangGuy's Avatar
This is my custom title

Posts: 1,779
Redirect non www links to www links via this code in your .htaccess:

Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteRule (.*) http://www.domain.com/$1 [L,R=301]
__________________
Mustang Evolution - Ford Mustang Enthusiast Website
Music Forums - General Music Discussion Forum

BamaStangGuy is offline
Reply With Quote
View Public Profile Visit BamaStangGuy's homepage!
 
Reply     « Reply to cookie problem www. and no www.
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13798 seconds with 12 queries