Solved

Cookies Problem

Posted on 2002-05-30
4
205 Views
Last Modified: 2006-11-17
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
Comment
Question by:Budenk
  • 2
4 Comments
 

Expert Comment

by:raja_velpuru
ID: 7044744
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
 

Author Comment

by:Budenk
ID: 7044890
Raja,

Could you please tell me how to do that.

Thanks.
0
 

Accepted Solution

by:
raja_velpuru earned 50 total points
ID: 7044941
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
 
LVL 2

Expert Comment

by:allie
ID: 7047590
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now