2

In my server-client model I'm using java for client side and for server side scripting using php5.

For communication I'm using simple http protocol.

In server I have some $SESSION variables(in php). I want access these variables in my java client.

How can it be posssible?

Thanks in advance.

7
  • 1
    This is JavaScript and not Java! Commented Feb 28, 2011 at 9:53
  • How can a web developer not know the difference between javascript and java? Commented Feb 28, 2011 at 9:56
  • See...I am making my own client in java. (I'm not using browser) Commented Feb 28, 2011 at 9:57
  • @adarshr - I'm asking for JAVA solution... @Richard - yup,how can a web developer not know the difference between javascript and java?!! he should know as I know the diffrence... Commented Feb 28, 2011 at 10:00
  • 2
    Could you please define "Most of us"?? If I write "JAVA" that means it is java...And though I am new to stackoverflow I know what is the ratio of java questions to javascript question. In my question I have written "..I'm using java for client side.." clearly. Commented Feb 28, 2011 at 10:59

5 Answers 5

3

AFAIK session variables is a server-side variables, that can be accessed by session id. You must refactor you application (to make java-client free of server side information) or send them (variables) from server to client manually.

Sign up to request clarification or add additional context in comments.

6 Comments

sure, I mean pure java-client. Not javascript.
Can you please elaborate a bit "AFAIK session variables" or u can give any link regarding that?
AFAIK is an acronym meaning "as far as I know."
@Richard Pianka - thnks .I thought it wud some kind of API library :P
Explain the problem that you have. May be we can find solution that will work. Think yourself: if session variables on server can be accessed by remote client without any problems than you have a LARGE security hole in your app.
|
2

You should use cookies instead of session variables if you're planning on sending it to the client side.

5 Comments

He's actually talking about a java application and not a browser environment
Actually, server side scripting is done.I have used there SESSION variables..So it wont be possible to change all the code right now.
@JohnP I never said he was using a browser and considering he's using http, he can still use cookies. Don't assume that I'm assuming something.
@JohnP - in java client also we can handle cookie. @Richard - you are correct
@Richard I'm sorry, I misunderstood your reply. And seeing the OPs comment he can use cookies on the client side. @Richard, could you just edit your reply so I can take back my downvote?
1

Your Java-client will make requests to the server, and the server will act like a web service, right?

If so, include all/any $_SESSION variables you might need with the XML/json/whatever response that the server sends back to the clients, something along the lines of:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<reply>
  <request>
    <method>getUsers</method>
    <param name="page">1</param>
    <param name="apiKey">API_KEY</param>
    <param name="sessId">SESSION_ID</param>
  </request>
  <response>
    <status>
      <code>0</code>
      <message>OK</message>
    </status>
    <users>
      <!-- Request reply here -->
    </users>
    <session>
      <variable1>$_SESSION['var1']</variable1>
      <!-- Additional session variables you might need on the client here[...] -->
    </session>
  </response>
</reply>

The thing is, session variables are something the server uses to keep track of which client is accessing it now, and relate data to that particular client. If you need this information on the client, perhaps you could refactor the application to create this data on the client and pass it to the server in case the server needs that data?

1 Comment

Got the point and many thanks for understanding my question (many ppl down voted my question :()
0

Simple.

<script type="text/javascript">
    var variable = '<?php echo $SESSION["variable_name"];?>';
</script>

1 Comment

Sorry I'm not making a webpage.I'm making my own java client.So your javascript code wont work for me.
0

The only thing you have to understand is that session variables has no difference from any other PHP variable.
Thus, you have to request it from PHP as well.
Of course, supplying a request with session identifier got from the previous calls. That's all, not a rocket science.

1 Comment

I see what you mean but "session variables has no difference from any other PHP variable." whilst accurate for the current question is actually wildly inaccurate. I'm sure you know this but you may want to put some scope on your answer :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.