Last active
August 29, 2015 14:05
-
-
Save TCotton/b68470623ba061580d06 to your computer and use it in GitHub Desktop.
Log JavaScript errors server-side with this simple PHP script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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