Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 Posts

    setting cookie on 2 locations

    How can i set a cookie on 2 different locations? The problem i have now is that if i go to http://www.domain.com it recognize the cookie, but when i go to http://domain.com (without the www.) the cookie doesn't show up... So is there a way i can set them on both locations?

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,044
    Thanks
    2
    Thanked 316 Times in 308 Posts
    A) You should actually pick one version of the domain name and use that in all links on your site and redirect visitors from the version you don't generally want to the version you do want to use. By being consistent and always using only one version, it will help your search engine page rank (or so I have been told.)

    B) By default, the session.cookie_domain setting (none) will cause the session cookie to only match the domain where the cookie was set at. From the manual -
    session.cookie_domain string
    session.cookie_domain specifies the domain to set in session_cookie. Default is none at all meaning the host name of the server which generated the cookie according to cookies specification.
    By setting the session.cookie_domain to be .domain.com (including the leading dot), it will match both www.domain.com and domain.com. See the following from the setcookie() description in the manual for more information -
    domain
    The domain that the cookie is available. To make the cookie available on all subdomains of example.com then you'd set it to '.example.com'. The . is not required but makes it compatible with more browsers. Setting it to www.example.com will make the cookie only available in the www subdomain
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •