Search code examples
javascriptphppaypal-ipnsetcookie

Why can't I set a cookie in my Paypal IPN file


My Paypal ipn file works fine - once verified I can add the payer to my sql database and write to a log file on my server, but setcookie doesn't seem to work. I want to simply set a flag so I know this person has paid. How else can I set a flag so my Javascript code knows they have paid?


Solution

  • The IPN request is made by a PayPal server, not by the user's web browser. You can't set cookies in a user agent that didn't make a request!

    To use PayPal for a membership system, you need to do a couple of things:

    • Have a user login system that uses a database. Hopefully you have this already! Include a column for having paid in the database table which contains users.

    • Include some data in the payment which identifies the user that's paying. For instance, include the user's ID in the invoice field.

    • When you receive a verified IPN, read the user's ID out of the invoice field and update the appropriate row in the database.