Search code examples
phpvariablescookiesmybbcoinpayments-api

Storing $award_id in a cookie - PHP


I have created a MYBB forum wadakela.xyz. I have added newPoints Awards System in it. Which is integrated with CoinPayments for user to buy it.

img: https://i.sstatic.net/vU3G6.png

Now, for example I have 5 awards and user buys 3rd one. I have scripted files which send an email and PM to me notifying that "this" user has purchased an award with ''this award ID'' when the user gets on success (callback from coinpayment) page.

imgs: https://i.sstatic.net/pRFhC.jpg

Initially, when it was not integrated with coinpayments, I used POST method to get the award ID from the form when someone clicks BUY button through awards page which actually was working fine. I could get the proper id using this code.

//awards page
<input type="hidden" name="award" value="{$award['aid']}">

//success page
$award_id = $_POST['award'];

Now that it is integrated with CoinPayments, it's not going to the success.php directly so POST method isn't working. If I'm not wrong, I can get the award id in the success.php via cookies (or sessions maybe?). But, I'm failing to store award ID in a cookie.

As we know, it's now like this:

-awards page -> coinpayments site -> success page.

To get award ID from awards page to success page, I tried the following code to store award ID into the cookie:

//in awards page
setcookie("award",$award['aid'], time()+300);

//in the form
<input type="hidden" name="award" value="{$award['aid']}">


....processing with coinpayments....



//in success (callback) page
$award_id = $_COOKIE["award"];

echo $award_id;  //pm + email actually.

setcookie("award",$award_id, time()-60);

in success page, $award_id Always returns "5". Maybe because there are 5 awards listed?

Other than this, the whole process is very smooth and working as intended. What I want to do is to store proper award ID in the cookie.

I'd appreciate if one could help me with this. And if there's any alternate to achieve this, I'd like to know about it as well.

And also, I really need to get it done by today..

If you need more information, please let me know.

Thank you. :)


Solution

  • Success URL doesn't work as IPN. Instead, IPN is required to return POST data.

    <input type="hidden" name="ipn_url" value="https://wadakela.xyz/YOURIPNFILE.php">
    <input type="hidden" name="ipn_type" value="simple">
    

    here YOURIPNFILE will return the POSTed data.