So i am trying to create a form that captures the users name (input) and the users IP (Hidden Input) and then writes it to a txt file. The IP should also display on the page showing the user the IP we are recording but the IP does not show up and the form does not write to the file but I can not figure out why.
Index.html:
<html>
<body>
<br />
<center>
<form action="writetotxt.php" method="POST">
<input name="field1" type="text" />
<input type="hidden" name="field2" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" />
<input type="submit" name="submit" value="Save Data">
</form>
Your IP:<?php echo $_SERVER['REMOTE_ADDR']; ?> will be recorded!
</center>
<br />
</body>
</html>
and writetotxt.php:
<?php
if(isset($_POST['field1']) && isset($_POST['field2'])) {
$data = $_POST['field1'] . '-' . $_POST['field2'] . "\n";
$ret = file_put_contents('mydata.txt', $data, FILE_APPEND | 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');
}?>
any ideas?
Edit: Form at: http://tsukino.forgewareinc.com/index.php
Edit2: So the real reason the form would not work correctly was due to file ownership that has now been fixxed