Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Static counter
Hi all ;)
I need advice. I use the paypal link “success return” in order to update a “stock” custom field by checking a parameter into URL (the article ID).
To avoid multiple decrementations on page reloading, I want to add a simple counter set to 1
that change to 0
after processing.
I tried to add a static variable, but I failed…
Here is the code into my “thank-you” page:
<txp:php>
/**
*
* Check the Paypal referer ("www.paypal.com")
* and decrease the corresponding custom_field.
*
* Page dependency: "occasions" or globaly if
* product stocks have to be updated.
*
*/
if (parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST) === 'www.paypal.com' && 0 != $count) {
if (null != gps('sid')) {
static $count = 1;
safe_update('textpattern', "custom_7 = custom_7 - 1", "ID = '".gps('sid')."'");
safe_repair('textpattern', $debug = false);
--$count;
}
}
</txp:php>
Last edited by Pat64 (2020-07-12 06:31:48)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: Static counter
A static variable, or any variable, will only survive a single page load. Once you refresh, it’s gone and needs to be set again.
You’ll need to set some flag in the database to be sure. Something in the article maybe? Or some unique token in the txp_token table with a long expiry? You can then look for that token via the incoming sid. The txp_token table has a reference column that you can use to set the article id of the article just processed.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Static counter
Ok. Thanks lot Stef.
I will investigate.
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Pages: 1