Before discussing this script in detail, you need to set up your IPN URL. When a customer on your website clicks the Buy Now button, they will be taken to PayPal for payment. After this successful transaction, PayPal's server sends an IPN message which essentially contains all the information relating to the transaction (product purchased, transaction number, amount paid, etc) to your IPN URL.
If you upload the IPN PHP script to the "paypal_ipn_demo" folder, the IPN URL, for example, will be: http://www.example.com/paypal_ipn_demo/ipnhandler.php.
How are you going to inform PayPal of your IPN URL?
Note: Since you are still testing your application, you will use the PayPal Sandbox to set your IPN URL and test your scripts.