Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have apache installed, and I would like (using php/and or javascript, html) to do the following but I do not know how.

  1. To send my client to the server a value x
  2. The server to increase x by one and to send it to client
  3. Client divides it by two and sends it to server
  4. server send the h((x+1)/2) back to client

How I can do that?... I am confused as I do not know how to make a server and a browser to communicate. |However, I do not thing that it is very difficult...

Thanks in advance

share|improve this question

closed as off topic by bybe, Su', John Conde May 12 '13 at 13:47

Questions on Webmasters Stack Exchange are expected to relate to webmastering within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Maybe host/?value=x and $__GET['value'] would give you some insight to provide me more detailed question. –  user2054689 May 11 '13 at 14:06

2 Answers 2

You would like to use Ajax. I would recommend you use some kind of javascript library to handle the ajax calls.

"With Ajax, web applications can send data to and retrieve data from a server."

Here is a sample.

Javascript (jquery)

var x, divided, result;
x = 6;

divided = $.ajax({
    type: "GET",
    url: "serverside.php?x=" + x,
    cache: false,
    async: false
    }).responseText;

divided = divided / 2;

result = $.ajax({
    type: "GET",
    url: "serverside.php?laststage=" + divided,
    cache: false,
    async: false
    }).responseText;

alert(result);

PHP

<?php
if (isset($_GET['x'])) {
    $x = $_GET['x'];
    $x++;
    echo $x;
}

if (isset($_GET['laststage'])) {
    echo $_GET['laststage'];
}
share|improve this answer
    
Thank you use555. I guess I'll have to go to bed now, but I will definitely try it tomorrow :) I vote up your answer for your time spend at my question and your effort:) Tomorrow I will try all the answers, and choose as best answer the answer that solves better my problem. Thanks a lot again. –  Andreas May 11 '13 at 20:14
    
edit: I just found out that I do not have enough reputation to vote up. As soon as I get, I'll definitely vote up your answer. Excuse me.. my mistake.. –  Andreas May 11 '13 at 20:23

Here is a very simple PHP script to get you started:

<?php 
 if($_GET['v']){
   echo intval($_GET['v'])+1;
 }
?>

<form>
Enter a value: <input type=text name=v>
<input type=submit>
</form>

I saved that as test.php in my www documents folder. The I opened it as http://localhost/test.php and was able to submit a number and verify that the script added 1 to it and showed me the result.

share|improve this answer
    
Thank you Stephen. I guess I'll have to go to bed now, but I will definitely try it tomorrow :) I vote up your answer for your time spend at my question and your effort:) Tomorrow I will try all the answers, and choose as best answer the answer that solves better my problem. Thanks a lot again. –  Andreas May 11 '13 at 20:14
    
edit: I just found out that I do not have enough reputation to vote up. As soon as I get, I'll definitely vote up your answer. Excuse me.. my mistake.. –  Andreas May 11 '13 at 20:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.