Skip to content

Instantly share code, notes, and snippets.

@TCotton
Last active August 29, 2015 14:05
Show Gist options
  • Save TCotton/b68470623ba061580d06 to your computer and use it in GitHub Desktop.
Save TCotton/b68470623ba061580d06 to your computer and use it in GitHub Desktop.
Log JavaScript errors server-side with this simple PHP script
<?php
if (isset($_GET) && count($_GET) > 0) {
function logErrors($fh, array $fields, $delimiter = ',', $enclosure = '"', $mysql_null = false) {
if (is_writable($fh)) {
$filename = $fh;
if (!$handle = fopen($fh, 'a+')) {
echo "Cannot open file ($filename)";
exit;
}
$objDateTime = new DateTime('NOW');
if (fwrite($handle, 'date/time' . ': ' . $objDateTime->format(DateTime::RFC822) . "\n") === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
foreach ($_GET as $key => $value) {
if (fwrite($handle, $key . ': ' . stripslashes($value) . "\n") === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
}
if (fwrite($handle, "\n") === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
fclose($handle);
} else {
echo "The file $filename is not writable";
}
}
logErrors('elevaate-errors.txt', $_GET);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment