tags:

views:

50

answers:

4

I'm currently testing a script on my host. This script is to accept PayPal IPN data, do a couple of things (ie. data verification), send necessary data to a specific email address, and more.

I'm using a test tool on the PayPal site to post test data to my script. My script doesn't work: there should be a code issued but I can't see the error. The test tool in PayPal just does the post and doesn't seem to accept any response. I want to see what happened in my script so that I can fix it. How can I get error messages my script outputs?

Any ideas?

+1  A: 

In these sort of cases, you should see what the $_POST array is printing in the console. Try using the following code at the very beginning of your page, after initializing with all the required configurations:-

<?php
// include all required configurations
// if needed, include the header file also

echo '<pre>';
print_r($_POST); // for viewing it as an array
var_dump($_POST); // for viewing all info of the array
echo '</pre>';
die();

// other HTML or PHP Logic follows
?>

If this does not work, then you will need to put some breakpoints, by putting some "exit" statements after some code every now & then, and slowly execute as much code as possible in a step-by-step manner.

Hope it helps.

Knowledge Craving
imho, better to use `var_dump($_POST)`
Kirzilla
@Kirzilla - updated answer. Thanks.
Knowledge Craving
$_POST is all correct, it is produced by paypal and i've sent it to my mailbox to take a look, all correct. There is some issue in my script, but i cannot see the error.
Edward
+1  A: 

Not sure if you tested this already (put at the very beginning of your PHP script):

error_reporting(-1);
ini_set('display_errors', 'On');

if it's not showing, try it with an .htaccess (if on Apache):

php_flag display_errors on
php_value error_reporting -1

with this you should get your error. If not, try your server logs or if it's still don't help, try to echo some control values to find where it crash...

Of course this is only for debugging purpose and you should turn that OFF when in production.

AlexV
the display_errors is on, the errors must be returned, but the test page simple ignore any response, maybe just drop the response packets.
Edward
Try to set them ON with an .htaccess if you did not. Sometimes when theres a syntax error PHP issue an HTTP 500 error and display a blank page ever if errors are ON. Setting them ON with an .htaccess can help in these cases. If not try to check your server logs.
AlexV
A: 

use log files and then read them.

Basically at the start of the script open a file then at various points in code dump some variables to that file, then you can go through that file and examine the output and in this way you can see what is wrong with your script

Ramuns Usovs
That is what i'm using now, but in this way i cannot know what the error is. I can locate to exact which line went to wrong, but don't know what's wrong with this line. Can only depends on experience to analysis...Maybe there is no way to get error message in this case, i'm afraid so though i'm who raised this question
Edward
See the post by GingerDog - this way you can log php errors to a file and read that.
Ramuns Usovs
+1  A: 

A better approach would be to log the errors to a file, and not the 'screen'. If you make a server wide change, it's probable that other sites on the server will be affected.

  • log_errors = On
  • display_errors = Off
  • error_log = /tmp/php.log (or a better path of your choosing; file probably needs to be writable by Apache/webserver).

Failing all of the above, install xdebug and try debugging the code - you can step through line by line and inspect variables at will - perhaps this will give you a better idea.

Failing that, resort to var_dump() and friends.

GingerDog