Solved

Cookies Problem

Posted on 2002-05-30
4
222 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

724 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