Solved

Cookies Problem

Posted on 2002-05-30
4
202 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
Comment Utility
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
Comment Utility
Raja,

Could you please tell me how to do that.

Thanks.
0
 

Accepted Solution

by:
raja_velpuru earned 50 total points
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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

12 Experts available now in Live!

Get 1:1 Help Now