[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

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


0
Budenk
Asked:
Budenk
  • 2
1 Solution
 
raja_velpuruCommented:
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.
0
 
BudenkAuthor Commented:
Raja,

Could you please tell me how to do that.

Thanks.
0
 
raja_velpuruCommented:
Try this out.

response.cookies ("MyCookie").domain = "myURL.com"
response.cookies ("MyCookie")("MyValue") = 99
response.cookies ("MyCookie").expires = DATE + 1

response.cookies ("MyCookie").domain = "www.myURL.com"
response.cookies ("MyCookie")("MyValue") = 99
response.cookies ("MyCookie").expires = DATE + 1
0
 
allieCommented:
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
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now