Reputation: 2664
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.
Upvotes: 0
Views: 209
Reputation: 6389
use $_GET
instead of $_POST
<form action="test.php" method="GET">
Then, deal with $_GET
instead of $_POST
in your PHP script
Upvotes: 3