1

How to access $_SESSION in jQuery ?

I'm developing a existing chat using jQuery with PHP. here is the code

function createChatBox(chatboxtitle,minimizeChatBox) {
    if ($("#chatbox_"+chatboxtitle).length > 0) {
        if ($("#chatbox_"+chatboxtitle).css('display') == 'none') {
            $("#chatbox_"+chatboxtitle).css('display','block');
            restructureChatBoxes();
        }
        $("#chatbox_"+chatboxtitle+" .chatboxtextarea").focus();
        return;
    }

    $(" <div />" ).attr("id","chatbox_"+chatboxtitle)
    .addClass("chatbox")
    .html('<div class="chatboxhead"><div class="chatboxtitle"><a href="javascript:void(0)" onclick="javascript:toggleChatBoxGrowth(\''+chatboxtitle+'\')">'+chatboxtitle+'</a></div><div class="chatboxoptions"><a href="javascript:void(0)" onclick="javascript:toggleChatBoxGrowth(\''+chatboxtitle+'\')">-</a> &nbsp;  <a href="javascript:void(0)" onclick="javascript:closeChatBox(\''+chatboxtitle+'\')">X</a></div><br clear="all"/></div><div class="chatboxcontent"></div><div class="chatboxinput"><textarea class="chatboxtextarea" onkeydown="javascript:return checkChatBoxInputKey(event,this,\''+chatboxtitle+'\');"></textarea></div>')
    .appendTo($( "body" ));

    $("#chatbox_"+chatboxtitle).css('bottom', '0px');
);


**The perameter **+chatboxtitle+** will display the username which is passed to this function. now i want to display the fistname of the user using session in this following line**

`   .html('<div class="chatboxhead"><div class="chatboxtitle"><a href="javascript:void(0)" onclick="javascript:toggleChatBoxGrowth(\''+chatboxtitle+'\')">'+chatboxtitle+'</a></div><div class="chatboxoptions"><a href="javascript:void(0)" onclick="javascript:toggleChatBoxGrowth(\''+chatboxtitle+'\')">-</a> &nbsp;  <a href="javascript:void(0)" onclick="javascript:closeChatBox(\''+chatboxtitle+'\')">X</a></div><br clear="all"/></div><div class="chatboxcontent"></div><div class="chatboxinput"><textarea class="chatboxtextarea" onkeydown="javascript:return checkChatBoxInputKey(event,this,\''+chatboxtitle+'\');"></textarea></div>')`

I want to use the session variable $_SESSION['user']; over there ? is it possible ? or we can call another perameter ? please help me i'm stuck with this..
Votes + Comments
http://www.lajm-shqip.com/
2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by pritaeas
1

You cannot use it as is, since a session is stored on the server. You could create a php script to expose it to jquery with an ajax call, or use cookies instead.

0

Thanks for your fast reply bro. Could you please help me with $_COOKIE insertion in that code ? because i need it urgently

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.