Author |
Message |
Andy
|
Posted: Wed Jul 30, 2008 8:19 am Post subject: Cookies |
|
|
Hey guys, quick question about cookies.
suppose I ran a site on the domain randomsite.com, and a couple of my pages use cookies
my friend also runs a site under my subdomain: sd.randomsite.com
is there a way to prevent having the users cookies from my site sent to him?
i know one way is to run my site under www.randomsite.com, and then have the cookies domain set to that, but is there a way around that?
thanks! |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Brightguy
![](http://compsci.ca/v3/uploads/user_avatars/527435178485ad4c287538.gif)
|
Posted: Wed Jul 30, 2008 9:22 am Post subject: Re: Cookies |
|
|
If the Host is .randomsite.com, Firefox will send the cookie to any site on that domain. Remove the leading period for the behaviour you want. I haven't tried other browsers... |
|
|
|
|
![](images/spacer.gif) |
Andy
|
Posted: Wed Jul 30, 2008 11:09 am Post subject: Re: Cookies |
|
|
what if i occupied several subdomains on my domain? ie
sd1.randomsite.com, sd2.randomsite.com, sd3.randomsite.com, randomsite.com, www.randomsite.com
and my friend only occupied the sd1.randomsite.com subdomain
is there a way for me to keep my cookies working for all of my sites, but not his?
thanks |
|
|
|
|
![](images/spacer.gif) |
md
![](http://compsci.ca/v3/uploads/user_avatars/1849317514ed6c4399768d.png)
|
Posted: Wed Jul 30, 2008 11:29 am Post subject: RE:Cookies |
|
|
nope.
You shouldn't be using cookies for anything requiring cookies anyways. Assume that any cookies you set can be read by everyone and build your security around that. |
|
|
|
|
![](images/spacer.gif) |
octopi
![](http://compsci.ca/v3/uploads/user_avatars/1246682444a1aa25749124.gif)
|
Posted: Wed Jul 30, 2008 1:01 pm Post subject: Re: Cookies |
|
|
Andy, when you set your cookies, make a function that sets the same cookie for all your domains.
So you'll be setting 5 different cookies for example, one each for each sub-domain you want. |
|
|
|
|
![](images/spacer.gif) |
jeffgreco13
![](http://compsci.ca/v3/uploads/user_avatars/21290830414888dd996a022.jpg)
|
Posted: Wed Jul 30, 2008 1:31 pm Post subject: Re: Cookies |
|
|
Are you trying to store secure information via this cookie?
Give us an idea of what information is to be held in the cookie. There is not way to restrict access to cookies from sub-domains, but Octopi might have a point and just have the browser load a specific cookie for each sub-domain. |
|
|
|
|
![](images/spacer.gif) |
octopi
![](http://compsci.ca/v3/uploads/user_avatars/1246682444a1aa25749124.gif)
|
Posted: Wed Jul 30, 2008 2:34 pm Post subject: Re: Cookies |
|
|
You might also be able to unset the cookies for his specific domain, but I'm not sure if that would work or not.
Basically you could try setting the cookies for all domains, then set another cookie for his specific domain but set a blank value.
Also if your worried about him reading and using any data in them, you could encrypt the cookies with some sort of encryption like AES (or one of many, many different types) |
|
|
|
|
![](images/spacer.gif) |
Andy
|
Posted: Thu Jul 31, 2008 8:39 am Post subject: Re: Cookies |
|
|
octopi @ Wed Jul 30, 2008 12:34 pm wrote: You might also be able to unset the cookies for his specific domain, but I'm not sure if that would work or not.
Basically you could try setting the cookies for all domains, then set another cookie for his specific domain but set a blank value.
then when the user visits his subdomain, cookies from my domain will not be appended to the get request?
Here's another question, are cookies appended to all get requests? even requests for images?
If i had a website www.abcdefg.com and had a cookie for the domain, would a get request for the image www.abcdefg.com/pic1.jpg also contain the cookie?
thanks |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Thu Jul 31, 2008 3:28 pm Post subject: Re: Cookies |
|
|
Andy @ Thu Jul 31, 2008 8:39 am wrote: Here's another question, are cookies appended to all get requests? even requests for images?
Yes. Remember that an image is just a response to a request. A *.php page could return an image, for example.
So one of service optimizations is to host static images on their own subdomain (or sometimes full out domain), so that all requests are cookie~less. Most of high-volume websites do this. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
Andy
|
Posted: Thu Jul 31, 2008 3:42 pm Post subject: RE:Cookies |
|
|
I figured out an alternative solution to my problem. Thanks guys! |
|
|
|
|
![](images/spacer.gif) |
jeffgreco13
![](http://compsci.ca/v3/uploads/user_avatars/21290830414888dd996a022.jpg)
|
Posted: Fri Aug 01, 2008 8:47 am Post subject: RE:Cookies |
|
|
Well?? tell us what you've come up with.... |
|
|
|
|
![](images/spacer.gif) |
Andy
|
Posted: Fri Aug 01, 2008 10:43 am Post subject: RE:Cookies |
|
|
oh, i noticed cookies have nothing to do with ip address, and is purely about domain. so instead of giving my friend a subdomain, i'll just have him run a different webserver. |
|
|
|
|
![](images/spacer.gif) |
|