ASP Cookies working and not working?

I have the below ASP functions that I use for cookies. If I visit my webiste with www, the cookies stay cross folders, however if I visit my website without the www the cookies get emptied.

When the user fills out the login form the login script is ran in a seperate folder where the user will be sent. However, as stated above if they login from the www they stay logged in otherwise they don't.

Also when the website is pulled up, I have an if statement that checks if the cookie is empty if it is set it equal to 0.

function GetCookie(Cookie)
      GetCookie = request.cookies(cookie)
end function

sub SetCookie(Cookie,Val)
      response.Cookies(Cookie) = Val
end sub
If Statement for when the site is pulled up:

if getcookie("MyCompany_id") = "" then
      setcookie "MyCompany_id",0
end if
Who is Participating?
sounds like you may need to add some code to your pages to check for the www in the url.  you should be able to search inside the URL server variable for that, and then redirect to the full url if the www doesnt exist.
2 different domains, 2 different cookies  (and yes that include leaving off the www or not)
OK , this is TRUE. becuse domain name with WWW and without that is diffrent but in some host server they refer WWW subdomain to ROOT domain. but when you create a cookie that cookie is encrypted with domain name and also will be diffrent if you use WWW in your address or not. This is becuse of Security I don't thing have any problem
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.