Uitlezen .domein.com cookie

Status
Niet open voor verdere reacties.

webinfo123

Nieuwe gebruiker
Lid geworden
15 mei 2009
Berichten
1
Ik probeer de cookie van phpbb uit te lezen dmv javascript. Als je inlogt met phpbb dan wordt er een cookie geplaatst die meestal de vorm phpbb3_abc_sid (abc is een willekeurig gekozen, maar altijd dezelfde code) heeft. Het cookie wordt geplaatst voor .domein.com en zou dus op alle subdomeinen van domein.com leesbaar moeten zijn.

Als ik alert(document.cookie); op bijvoorbeeld www.domein.com uitvoer, zie ik de cookie (phpbb3_abc_sid) van phpbb niet staan.

Wie weet waarom dit niet werk en/of hoe ik het cookie wel uit kan lezen met javascript?

Als ik in Firefox (web developer add-on) alle cookies bekijken, dan zie ik cookie phpbb3_abc_sid echter wel staan. Ook valt het me op dat als ik op www.domein.com het stukje javascript start, dat alleen de cookies voor het domein .www.domein.com zichtbaar zijn.

Voor de volledigheid. Dezelfde situatie doet zich voor met IE en FF. De cookie wordt gezet op forum.domein.com. Ik heb op internet gezocht naar de reden dat dit niet werkt. Ik kon er eigenlijk niets over vinden.
 
Het cookie wordt geplaatst voor .domein.com en zou dus op alle subdomeinen van domein.com leesbaar moeten zijn.
Nope, dat is niet zo. Dit uiteraard vanwege security.

If you use cookies in your website, a cookie set from a subdomain
cannot be read from the main domain and vice versa because of the security
association feature tied to the domain which set it. This is also true for
session cookies, where, if the user is logged in on the main site, and
then moves to a subdomain, the subdomain site will not be able to access the
same session cookie, and will assign a new session (hence forcing the user
to login again).
(http://content.websitegear.com/article/subdomain_tips.htm)

Also uit die link:
If the cookie domain is set to ".domain.ext", it will not be accessible by a user
who types in the address without the www before the domain (i.e. http://domain.ext).
Therefore, redirect all requests without www to http://www.domain.ext.
 
Laatst bewerkt:
Het cookie wordt geplaatst voor .domein.com en zou dus op alle subdomeinen van domein.com leesbaar moeten zijn.
Nope, dat is niet zo. Dit uiteraard vanwege security.
Dit is wel mogelijk.

domein.com -> hier zijn de cookies alleen beschikbaar voor domein.com en niet voor de subdomeinen
.domein.com -> hier zijn de cookies beschikbaar voor domein.com en alle subdomeinen

Bron: http://php.net/manual/en/function.setcookie.php

The domain that the cookie is available. To make the cookie available on all subdomains of example.com then you'd set it to '.example.com'. The . is not required but makes it compatible with more browsers. Setting it to www.example.com will make the cookie only available in the www subdomain. Refer to tail matching in the » spec for details.
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan