SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2004
    Location
    Farmington
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation How to read cookie from different path in the same domain

    I have three paths as follows within the same domain.

    http://mysite.company.com/path1
    http://mysite.company.com/path2
    http://mysite.company.com/path3

    When I am on site "http://mysite.company.com/path1", how do I read the cookie on "http://mysite.company.com/path2" and "http://mysite.company.com/path3" paths ?

    Here is my function to read the cookie but this takes only one parameter cookie name.
    function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);}
    return null;}

    Thanks for the help.

  2. #2
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can only specify a path when setting a cookie. It determines the highest level at which the cookie can be accessed. If you control all the code on the site, set all cookies with path=/.
    Tab-indentation is a crime against humanity.


Bookmarks

Posting Permissions

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