1

I have several API-s for performing some actions on my site with JSON response. Since PHP files are only accessed via AJAX, i want to change the way errors are shown.

Currently if error occurs it does something like this

die('Getting Result Error: (' . $this->sql->errno . ') ' . $this->sql->error);

So this will never get to the user (site owner) because JavaScript is handling JSON response

I'm thinking about switching to error_log

error_log('Getting Result Error: (' . $this->sql->errno . ') ' . $this->sql->error, 0);

Is this a better practice? What do you recommend.

Also I was thinking about just doing this

error_log('Getting Result Error: (' . $this->sql->errno . ') ' . $this->sql->error, 0);
header('Content-Type: application/json');
$arr = array("status"=>'error');
echo json_encode($arr, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);

So i notify my script something is wrong and user will se this error, and owner of site sees it in error log.

1 Answer 1

2

error_log has the option to send a message to a nominated email address:

$admin='[email protected]';
$headers= …;        //  as per mail() function
error_log($error,1,$admin,$headers);

This will notify the administrator.

I presume you would probably follow this with some sort of message back to the user.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.