简体   繁体   中英

posting data to php via url

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.

use $_GET instead of $_POST

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM