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?
-
setcookie set the cookies only after a page loading (If I remember correctly). That may be the cause of your problem. – Yasuu Jun 16 '17 at 15:11
-
You could chuck it into the session, then in your JS have something like `var isPaid = = !empty($_SESSION['paid']) ? "true" : "false"; ?>;` - it's a bit dirty but should do the job. – CD001 Jun 16 '17 at 15:22
2 Answers
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.
I found this solution, if it really is the server that does not set cookies before your check :
setcookie('uname', $uname, time()+60*30);
$_COOKIE['uname'] = $uname;
https://stackoverflow.com/a/3230167/7924393
If it can help.

- 165
- 7
-
No, that doesn't help at all. As I mentioned in my answer, the IPN request is being made by the wrong agent entirely -- cookies won't work for this at all. – Jun 16 '17 at 16:57