Are HTTP cookies port specific?

前端 未结 8 1880
傲寒
傲寒 2020-11-22 04:14

I have two HTTP services running on one machine. I just want to know if they share their cookies or whether the browser distinguishes between the two server sockets.

8条回答
  •  抹茶落季
    2020-11-22 05:08

    An alternative way to go around the problem, is to make the name of the session cookie be port related. For example:

    • mysession8080 for the server running on port 8080
    • mysession8000 for the server running on port 8000

    Your code could access the webserver configuration to find out which port your server uses, and name the cookie accordingly.

    Keep in mind that your application will receive both cookies, and you need to request the one that corresponds to your port.

    There is no need to have the exact port number in the cookie name, but this is more convenient.

    In general, the cookie name could encode any other parameter specific to the server instance you use, so it can be decoded by the right context.

提交回复
热议问题