Read Session Id using Javascript

前端 未结 7 1817
被撕碎了的回忆
被撕碎了的回忆 2020-12-24 06:33

Is it by any means possible to read the browser session id using javascript?

相关标签:
7条回答
  • 2020-12-24 07:10

    For PHP's PHPSESSID variable, this function works:

    function getPHPSessId() {
        var phpSessionId = document.cookie.match(/PHPSESSID=[A-Za-z0-9]+\;/i);
    
        if(phpSessionId == null) 
            return '';
    
        if(typeof(phpSessionId) == 'undefined')
            return '';
    
        if(phpSessionId.length <= 0)
            return '';
    
        phpSessionId = phpSessionId[0];
    
        var end = phpSessionId.lastIndexOf(';');
        if(end == -1) end = phpSessionId.length;
    
        return phpSessionId.substring(10, end);
    }
    
    0 讨论(0)
提交回复
热议问题