Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Txp human detection
I’ve been on the OCD warpath to reduce bots from crawling my website. With the help of this forum, I added cookies and then used them to prevent deep links . Progress!
I still get bots scarfing up articles. I do have a solution, which is to check for the cookie; if it isn’t there, ask the human to refresh. Awkward. I guess that would look like:
<txp:php>
if( cookie ) {
<Somehow tell Txp that I found a cookie! Who's a good boy!>
}
</txp:php>
(Txp checks variable and does smart things)
How does php set a Txp variable? (I bet there is already an overly complicated plugin for checking cookies…)
If I don’t want human interaction, I can do, at the very top of a Txp page:
<txp::php>
if( !cookie ) {
setcookie(...) ;
header( refresh:0 ) ;
<tell Txp to not display anything>
}
</txp::php>
Looks like an infinite loop if the browser is rejecting cookies. Do I need to do php session stuff here? Because yuk. Does Txp have session tracking?
Offline
Re: Txp human detection
There is a cookie plugin, oui_cookie which works very well. And if you want to track session info, you can do so via PHP’s $_SESSION
.
As far as using cookies in Txp, there are a few examples dotted around the core.
Inserting variables inside PHP blocks can be done in a few ways. From least to most future-proof:
<txp:variable name="my_var" value="Hello world" />
<txp:php>
global $variable;
echo $variable['my_var'];
</txp:php>
<txp:variable name="my_var" value="Hello world" />
// 4.9.0+ only
<txp:php my_var='<txp:variable name="my_var" />'>
echo $my_var;
</txp:php>
<txp:variable name="my_var" value="Hello world" />
<txp:php>
echo parse('<txp:variable name="my_var" />');
</txp:php>
Each one has a cost associated with performance vs maintenance. Oleg will be able to supply more concrete information on this but my rough guess would be that the above are in order of performance, fastest first, but is most likely to break first in future.
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: Txp human detection
Choices! I like all of them. I can do the non-refresh version with oui_cookie and no php at all.
TIL: A php session won’t help if cookies are disabled; php sessions set a cookie to track the session.
(ps…how did you get context coloring on your forum post?)
Last edited by skewray (Today 18:50:49)
Offline
Re: Txp human detection
skewray wrote #340549:
(ps…how did you get context coloring on your forum post?)
Add the language after the bc.
then your content beginning the next line.
bc. php
bc. txp
bc. html
Probably others (js? css? javascript? stylesheet?). I don’t have the definitive list we support to hand.
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