Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how browser relates the cookies for web sites in each tab

Tags:

java

cookies

How does the browser relates the cookies for the websites opened in tabs.for example in firefox i have opened five tabs and in each tab i have loaded different sites. my question is how browser identifies which cookies for which site. what is the relationship it has. similarly if i open the same sites in another browser instance , will the same cookie be used.

like image 699
Dead Programmer Avatar asked Aug 18 '10 17:08

Dead Programmer


People also ask

How are cookies shared between browsers?

Cookies are per-browser, but plugins (such as Flash) have their own storage and can be used to share information between browsers.

Is cookie shared across tabs?

Cookies are specific to websites. If you have multiple tabs open to various pages on the same site they'll share cookies. Tabs open to different websites don't have access to cookies used by another site regardless of whether it's open in another tab.

How do browsers handle cookies?

The browser may store the cookie and send it back to the same server with later requests. Typically, an HTTP cookie is used to tell if two requests come from the same browser—keeping a user logged in, for example. It remembers stateful information for the stateless HTTP protocol.

Are cookies different for each browser?

No, if they are non-persistent cookies they are deleted upon closing the browser and if they are persistent they are saved on the hard drive but are only used by a single browser. IP addresses can change all the time or be identical for two different browsers, they no way uniquely identify a client.


1 Answers

How does the browser relate the cookies for the websites opened in tabs.

Cookies have nothing to do with tabs or windows -- they have to do with requests to a domain. Whenever the browser makes a request to a webserver for a domain, any cookies that it has for that domain will be sent in the request header. Often there are 10s of requests made for each webpage to download the HTML, images, javascript, etc.. Each of those requests get sent with the cookies for the domain in the request. Here's a good page about how cookies work in case you don't know.

If you have 5 tabs to different webpages then the requests made in those tabs to the various different domains will have different cookies. If some content (for example an image) is shared across all sites, then the same cookie will be sent in all of the 5 requests. If you open the same webpage in another tab in the same browser then the same cookies will be used for requests for that domain.

If you open another browser "instance" then it depends probably on the browser and your OS. If the cookie is not a session cookie, i.e. if the cookie is stored to disk, then when you run another instance of Firefox, it should read/write to the same cookie file as the first instance. Often if you start another browser it may just start another window of your current browser so the cookies will be the same. If you run two different types of browsers then most likely the cookies will be separate although it depends on the browsers on whether they share the same cookie files.

It's also important to understand that one of the features of the "Incognito Window" (Chrome) or "Private Window" (Safari/Firefox) is that they have a separate cookie space that gets removed when all private windows are closed. This means that you can log into two gmail accounts (for example) at the same time because the normal and private windows have different sets of cookies. This is also very useful when you want to test a web-service and you want to make sure to have clear cookies.

like image 81
Gray Avatar answered Oct 22 '22 17:10

Gray