ASP Cookies working and not working?

Posted on 2006-04-13
Last Modified: 2008-02-01
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
Question by:hansam
    LVL 22

    Accepted Solution

    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.
    LVL 25

    Expert Comment

    2 different domains, 2 different cookies  (and yes that include leaving off the www or not)
    LVL 2

    Expert Comment

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    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…
    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…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 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

    11 Experts available now in Live!

    Get 1:1 Help Now