Link to home
Start Free TrialLog in
Avatar of Budenk
Budenk

asked on

Cookies Problem

I have an ASP file called testcookie.asp that contents this small script:
<%
response.cookies ("MyCookie")("MyValue") = 99
response.cookies ("MyCookie").expires = DATE + 1
%>

I also has an ASP file to write the cookie. It's called writecookie.asp.
Here what I put on that file.
Response.Write (Request.Cookies("MyCookie")("MyValue"))

Then, I run test cookie file (http://myURL.com/testcookie.asp). I didn't use www in front of the domain name.
When I run the write cookie file without typing www on front of the domain (http://myURL.com/writecookie.asp), it does not display the value of the cookie.
However, if I put "www", it works properly.

I also tried to run the test file by putting "www" in front of my domain name. Then, running the write file, and it works properly.

When I checked the cookies on the "cookies" folder, the script create two cookies files, one if for the file that I ran using "www", and the other one is for the one without "www".

Is there any way that make my cookie work in both, so I can still detect the same cookie whether the user is typing the URL with our without "www".

Thanks


Avatar of raja_velpuru
raja_velpuru

Budenk, you can set cookies specific to a domain also.

Set whatever cookies u want for both domains (i.e., with & without "www"). I guess that should work.

I can get you the syntax if you want.
Avatar of Budenk

ASKER

Raja,

Could you please tell me how to do that.

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of raja_velpuru
raja_velpuru

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just so you're aware of it, here's part of why you may have been experiencing this problem.  Cookies (as you noticed) are save with the full path of the page.  That's completely reasonable, since you may have muliple sites using a page name "default.asp", but each site will have a unique domain name.  HOWEVER, you should also know that it uses the ABSOLUTE, not the logical path... in other words, let's say you go to a site "www.abc.com/mypage.asp" and it writes a cookie that's used every time you visit that site.  Fine and dandy.  Now, let's assume that the ISP address for the domain name "abc.com" is 208.0.0.0.  If you go to the SAME PAGE using the address "www.208.0.0.0/mypage.asp" it won't find the cookie!  That's because the path you typed, while the same path logically, contains different characters.

raja_velpuru's suggestion looks like it's your best bet.  I ran into this problem because I was using a redirect without specifying the domain name.  We just grabbed the path the user had typed from the address bar and used that to redirect - that way they could get there using either domain or IP and it would work either way.  Good luck!'

allie