0

I have the following simple form:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Upload Lab Data</title>
    </head>
    <body>
        <form action="test.php" method="POST">
            <input name="ip" type="text" />
            <input name="data" type="text" />
            <input type="submit" name="submit" value="Save Data">
        </form>
    </body>
</html>

and the following php script:

<?php
    if(isset($_POST['data'])) {
        $data = $_POST['data']  . "\n";
        $ip = $_POST['ip'] . "\n";
        $ret = file_put_contents('/tmp/' . $ip, $data, LOCK_EX);
        if($ret === false) {
            die('There was an error writing this file');
        }
        else {
            echo "$ret bytes written to file";
        }
    }
    else {
        die('no post data to process');
    }
?>

It works fine, but how can I modify (or use as-is) so that I can submit the ip and data fields via the url? My end goal is to be able to submit data from a java program running on another server.

1 Answer 1

3

use $_GET instead of $_POST

<form action="test.php" method="GET">

Then, deal with $_GET instead of $_POST in your PHP script

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

2 Comments

Okay, that worked. Only issue now is that the $ip variable (my filename) has an "?" appended to the end of it when it gets written. Is there a way to remove that?
try removing . "\n" from $ip = $_POST['ip'] . "\n";

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.