Jump to content

Failed AJAX Call -- No PHP Error Tracks


iwato

Recommended Posts

BACKGROUND:  I have an AJAX request that cannot find the PHP processing file for which it is looking. It is returning a 500 error in my web console.  I have checked the PHP error log for that file and can find no error.  I have also checked the error logs for the PHP files related to the requested PHP file, as well as the error log of the requesting page.  Nothing. Nothing. Nothing. And, Nothing.  I have even asked the help of my server provider.  Nothing.  Needless to say, I am at a loss.

The functionality related to this AJAX call was created many months ago, and was working fine at the time of creation.   In fact, the same functionality used to work at three different locations.   I discovered the failure while performing a somewhat casual check in search for damage from suspected hackers.  Once hacked, you do not easily forget it.  it is kind of like being raped.

QUESTION: What would be a proper strategy for troubleshooting this failure?

AJAX CALL:

		$.ajax({
			type: "POST",
			url: '.../captcha_reset.php',
			data: {dataRequest: 'requestInstance'},
			statusCode: {
				404: function() {
				alert( "Page not found" );
			}},
			success: function(jsonData) {			
				jsonObj = JSON.parse(jsonData);
				captcha_sa = jsonObj.captcha_ra;
				$('.CaptchaLabel').css('background-color', jsonObj.captcha_rc);
				$('.CaptchaAnswer').val('');
				$('.CaptchaLabel').html(jsonObj.captcha_rq);
				$('.CaptchaError').css('display', 'none');			
			}
		});

CODE from REQUESTED PHP FILE:

	if ($_SERVER['REQUEST_METHOD'] == 'POST') {
		$captcha_reset = array();
		if ($_POST['dataRequest']) {
			$dataRequest = filter_var($_POST['dataRequest'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
			if ($dataRequest == 'requestInstance') {
				require_once '.../vendor/autoload.php';
				require_once '.../select_color_pair.incl.php';
				$color_pair = select_color_pair(true);
				$ictext_color = $color_pair['text_color'];
// 				$icbackground_color = $color_pair['bg_color'];				
				require_once('.../class.imageless_captcha.php');
				$captcha_r = new ImagelessCaptcha(3, false, false, $ictext_color);
				$captcha_reset['captcha_rq'] = $captcha_r->formPhrase();
				$captcha_reset['captcha_ra'] = $captcha_r->getInt();
				$captcha_reset['captcha_rc'] = $color_pair['bg_color'];
			}		
		}
		echo json_encode($captcha_reset);
	}

Please advise.

Roddy

 

Link to comment
Share on other sites

So I tried a couple of requests to the page mentioned and you've definitely isolated the problem code here. (Only a POST request with that payload errors)

I'd want to check if that logging system is working first.

Try introducing a syntax error and see if that comes up in the logs.

If it does, good! We know that works. We may be looking at something that is suppressing third-party code errors. (Maybe the '@' operator)

If it does not, you'll need to check your logging settings, make sure they're going to the correct location on your webhost.

Link to comment
Share on other sites

Hi Dsonesuk!  Happy New Year!

I purposefully wrote the paths as .../ in order to hide my file structure to the general public.  I wish it were that easy.

Roddy

 

Edited by iwato
Link to comment
Share on other sites

Hi, Funce!  Happy New Year!

The logging system is everywhere the same.  It appears as follows:

	error_reporting(E_ALL);
	ini_set('log_errors', 1);
	ini_set('error_log', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'error.log');
	ini_set('html_errors', 1);
	ini_set('display_errors', 0);

Roddy

Link to comment
Share on other sites

Addendum to Initial Entry

The following is a note that I wrote to myself about the problem:

•    The Imageless_Captcha functionality is failing again.

    •    Step One:  Open overview.html
    •    Step Two:  Click on Local Search/Newsletter, Local Search/Podcast, Local Search/Q&A on the overview.html page in either the production or development folder and the result is the same. The worded number phrase does not appear, rather the phrase "Enter something here!"
    •    Step Three:  Open the WebConsole in the Network panel and discover that the PHP file:
     /home/thege0/public_html/grammarcaptive.com/devcptv18rs/_utilities/php/captcha/captcha_reset.php
         
        has not been loaded.  And, the Error Code 500 appears.
        
    •    There is no trace of a PHP error anywhere.

Roddy

 

Link to comment
Share on other sites

Hi, Funce.  There are about five PHP error logs involved.  And, all of them contained error messages from the past that i erased.  So, I have assumed that they are working.  Just to be sure.  I will give it a try.  Just a moment.

Roddy

Link to comment
Share on other sites

Just now, iwato said:

Does this look like a good syntax error?

        var_dump(goofy);

Roddy

If it wasn't, I would be very concerned about how you're naming your defines.

Link to comment
Share on other sites

Actually it created a white sheet.

So, I introduced purposefully the error that Dsonesuk believed that I was making accidentally, and it produced a very nice error message.  So, yes, the errors are currently being reported.  Here is the resulting error message.  It may give a clue.

[05-Jan-2020 22:06:05 UTC] PHP Warning:  require_once(.../../../../../../vendor/autoload.php): failed to open stream: No such file or directory in /home/.../captcha_reset.php on line 17
[05-Jan-2020 22:06:05 UTC] PHP Fatal error:  require_once(): Failed opening required '.../../../../../../vendor/autoload.php' (include_path='.:/opt/cpanel/ea-php70/root/usr/share/pear') in /home/.../captcha_reset.php on line 17

Roddy

Edited by iwato
Link to comment
Share on other sites

Good, good. I want to see if any of those included files are silently erroring

Can you create a separate page that just includes them on their own, and see if that creates a 500 error?

Link to comment
Share on other sites

I am not sure what you mean.  Each of the other pages has its own error code, just like the one that I showed above.  Therefore, if an error occurs on any one of those pages, it should appear in that pages error code that is copied into the same folder as the page.  Well, I do not not know how others do it, but it is my work flow style.

Roddy

Link to comment
Share on other sites

I was referring to specifically these three lines. If the page errors with just these lines (and your error logging) then the error resides inside these pages.

<?php
require_once '.../vendor/autoload.php';
require_once '.../select_color_pair.incl.php';
require_once('.../class.imageless_captcha.php');

 

Link to comment
Share on other sites

I just checked the error logs for .../select_color_pair.incl.php  and .../class.imageless_captcha.php, but could find nothing.  And, the error log that should include the errors  for .../vendor/autoload.php shows nothing.  As I did not build autoload.php, its errors do not appear in the same folder -- namely, /vendor. 

I do see what you mean.  You wanna make me work....   Just a moment.

Roddy

Link to comment
Share on other sites

Alright.  I left the error code and the condition of the if-statement and eliminated all of the remaining processing code with the exception of those lines that you designated.  No error resulted.

Roddy

Link to comment
Share on other sites

Nothing. 

Nothing. 

Nothing. 

Nothing. 

Nothing. 

Nothing. 

I even tried a real var_dump that included the $dataRequest variable.  Also, you guessed it, Nothing.

Roddy

Link to comment
Share on other sites

1 minute ago, iwato said:

How about a composer update?

Roddy

 

Might be a good step. But you've just replaced all the lines, and the error hasn't come back? Or did it come back at an earlier step?

Link to comment
Share on other sites

I replaced each of the lines one at a time. With each newly unveiled line I checked the functionality in my browser, and the PHP error log.  At no point was any error code exhibited.  I even reset the line that I had previously commented out. Nothing.

I am currently researching how to update composer.  The number of composer.json files that I have is absolutely amazing.  They are everywhere and mostly places where I never have been and have no desire to go.

OK.  I have just updated with php composer.phar 

Roddy

Link to comment
Share on other sites

Yes, the file is now reported as loaded, and WebConsole is now reporting a Javascript error, but I am not sure from where.  Above is the only use of the JSON.parse command in the entire calling file.

success: function(jsonData) {			
    jsonObj = JSON.parse(jsonData);
    captcha_sa = jsonObj.captcha_ra;
    $('.CaptchaLabel').css('background-color', jsonObj.captcha_rc);
    $('.CaptchaAnswer').val('');
    $('.CaptchaLabel').html(jsonObj.captcha_rq);
    $('.CaptchaError').css('display', 'none');			
}

This is the error message:

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

Wow!  And, just when I thought things were looking bleak. :-)

Roddy

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...