Skip to content

Instantly share code, notes, and snippets.

@ericjames
Last active October 23, 2017 02:09
Show Gist options
  • Save ericjames/1472d6f347f236a415be4e2e85e51ffe to your computer and use it in GitHub Desktop.
Save ericjames/1472d6f347f236a415be4e2e85e51ffe to your computer and use it in GitHub Desktop.
PHP Save Feedback - A simple script to store some input field data into a local text file
<?php
$date = date ("l, F jS, Y");
$time = date ("h:i A");
$msg = "";
if ($_SERVER['REQUEST_METHOD'] == "POST") {
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "\n";
}
}
else {
foreach ($_GET as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "\n";
}
}
$file = 'feedback.txt';
$current = file_get_contents($file);
$current .= " -- \n";
$current .= $date . ' ' . $time . "\n";
$current .= $_SERVER['HTTP_USER_AGENT'] . "\n";
$current .= $msg;
if (file_put_contents($file, $current)) {
echo "yay";
} else {
echo "fail";
}
if ($msg == "") {
echo "fail message did not work";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment