0

I have a webpage provided by the server. I have about 20 different clients accessing this webpage. The webpage is a simple form with a textbox displaying to each client. Client is responsible for providing the input usually it would be through input device like a keyboard, microphone, barcode scanner etc. I have a different device which cannot directly input its value to the textbox but only through a variable value. Server is using WAMP and each client has LAMP installed on it.

I created a request for that input from the server using ajax call but that is not ideal and I do not want to put too much pressure onto the server. I just want the variable to be sent automatically to the webpage as it is being loaded by the client. I heard it can be done using cURL, but my question is what would be the best way to achieve this and how to do it? Would it be easier to send a variable from a shell to a web browser on the load? I’m looking for a secure but easy to implement method. This is what my attempt was: (although I got confused on how to approach this)

Server: (WAMP Server / server.php)

<?php

if(isset($POST)){
    $_POST['var'];
}

?>

<html>
<body>
<form action="" method="post">                                                                                              
    <input type="text" name='var' value="<?php echo "$var"; ?>"/>
</form>
</body>
</html>

Client: (LAMP Server / inputProv.php)

<?php

$var = "Hello";
echo $var;

?>

Client: (LAMP Server / send.php)

<script>
    $(document).ready(function(){
        $.get("http://localhost/inputProv.php", function(response) {
            $("input[name=var]").val(response):
        });
    });
</script>
5
  • What is $_POST(input)? $_POST is an array, not a function. Commented May 10, 2017 at 22:23
  • @Barmar should I echo the $input instead? Commented May 10, 2017 at 22:26
  • I don't know. It's not clear what you're trying to do with that variable. Commented May 10, 2017 at 22:29
  • @Barmar I want to display its value in the textbox as the form loads on a client machine. Commented May 10, 2017 at 22:30
  • How is that variable related to the question about putting the result of the script into the <input> field? Commented May 10, 2017 at 22:30

1 Answer 1

0

inputProv.php should just echo the variable.

<?php
$var = "Hello";
echo $var;

In your Javascript you use AJAX to fill in the input from this script.

$(document).ready(function() {
    $.get("http://localhost/inputProv.php", function(response) {
        $("input[name=var]").val(response);
    });
});
Sign up to request clarification or add additional context in comments.

15 Comments

this is not bad but there will be 20 different IP addresses do I need to get the content of each one? what if I do not know the IP of the client only client knows what is the address of the server?
If only the client knows, then it needs to make an AJAX request, you can't do it on the server when creating the page.
Can the client make an AJAX request directly to the LAMP server, so it doesn't have to load the WAMP server?
@Barman the main server is WAMP and each client should provide input to that web page on that server. If LAMP is sending the data to WAMP at a later stage then yes.
I've changed the answer to show how to get it using AJAX.
|

Your Answer

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