I understand how IPN works. Say my IPN page is pp.php. This is the page that posts the info back to paypal and finds out that everything is okay. But is pp.php also the page that says "Thank you here is your download link" whenever a customer pays, or do I need to set a return URL for that in my paypal settings? If so, how do I make sure that the payment went through on the return URL? Do I log the successful transaction in a database when I validate the info in pp.php, and then check it at the thankyou.php return URL?
The script that processes the ipn should not contain the DL link. Once the conditions you have set are met it should forward the purchaser to the page that contains the DL link. The more or less common way of doing it with a DB is to write the sale to the DB with a status of pending when the customer buys and then have the IPN script change the status to paid when the process completes. Sometimes this can take several days if an e-check is used.
Okay, so after I make sure the payment amount and everything is correct, i do a location: header to the thankyou/DL page?
I have never written one. My understanding is that PP sends the info, you send it back and they confirm that what you got and sent is correct. When that happens your script then says okay and does whatever. I am giving away a paypal store cgi script on one of my sites. Why don't you grab a free copy and see how someone else did it. Grab it quick. I need to update that site with some new stuff later this week.