1

Using Chrome's developer tools (tab Resources) or in Firefox's Tools (tab Storage) values like session tokens e.g. PHPSESSID can be seen. Question: How can that value be retrieved programatically? My question is not related with PHP (exclusively) but with, hopefully, Javascript. I mean, a standard way to get the values, all those shown on the mentioned tabs, at the browser side.

Addendum: If I make a request from the browser (I used an AJAX snippet) then checking in the server I can see the PHPSESSID So, there must be a way to get that value available directly from the browser.

Calamar
  • 1,547
  • 1
  • 13
  • 25

1 Answers1

-1
function getCookie(cname) {
    var name = cname + "=";
    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);
        if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
    }
    return "";
}

getCookie('PHPSESSID');
L00_Cyph3r
  • 669
  • 4
  • 18
  • 1
    This is not the answer to the question. The question was not how to read cookies with JavaScript but how the special `PHPSESSID` cookie can be read with JavaScript. – Michael Käfer May 09 '20 at 13:57