通过javascript从会话中提取用户名

I am trying to extract user logged-in name from client side i.e javascript. I am able to get cookie that is set at client side which stores current user session id. But how to get user name from that PHPSESSION ID ? And i dont want to use any API.
As session is set at server side I am unable to get that information.

Following is what i got, session id by document.cookie
Please help me out.

Thanks in advance

You might have set username in php global variable- $_SESSION['username']

You can extract this from javascript using the following line.

<script>
 var username="<?php echo $_SESSION['username']; ?>";
</script>