Skip to content

Instantly share code, notes, and snippets.

@ThomasArdal
Last active August 22, 2022 10:09
Show Gist options
  • Save ThomasArdal/d4d5ae986c1e51b83e086bcb68543899 to your computer and use it in GitHub Desktop.
Save ThomasArdal/d4d5ae986c1e51b83e086bcb68543899 to your computer and use it in GitHub Desktop.
Example of how to manually log an exception from PHP to elmah.io.
// Test
function logErrorElmahIO($logID, $title, $application, $critical = '0', $detail = '', $user = '') {
$ch = curl_init();
if ($critical == '1') {
$criticalStatus = "500";
} else {
$criticalStatus = "100";
}
$data = array(
"title" => $title,
"application" => $application,
"statusCode" => $criticalStatus,
"detail" => $detail,
"hostname" => $_SERVER['HTTP_HOST'],
"user" => $user,
"url" => $_SERVER['REQUEST_URI']
);
$data_string = json_encode($data);
$a = "https://elmah.io/api/v2/messages?logid=$logID";
curl_setopt($ch, CURLOPT_URL, $a);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
curl_close($ch);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment