Terence Eden. He has a beard and is smiling.

Terence Eden’s Blog

Theme Switcher:

Blunt Banhammer Blocks Basic Bots Ballistically

· 30 comments · 1,350 words · Viewed ~4,857 times


A confused little cardboard robot is lost amongst the daisies

I cut bot traffic to my site by over 80% with a simple trap. Last month, my hobby website OpenBenches.org transferred more than 2.5TB of data to visitors. As much as I'd like to think the site is enormously popular, it looks like it is just AI bots endlessly crawling the data and slurping up the images. So I've built B to be an indiscriminate tool to eradicate these unwanted parasites. It is…

Some quick thoughts on Unit Testing ActivityPub

· 3 comments · 600 words · Viewed ~2,430 times


The PHP logo.

I'll be radically honest here - I never really got the idea of "Test Driven Development". I'm much more of a "telnet into production and damn the consequences" kind of guy. Look, it's much more fun and my cardiologist recommends severe shocks every now and again. The essence of unit testing is pretty simple: Feed a function some data See how it responds Send it good data and if it returns…

A reasonably practical guide to validating RFC 9421 HTTP Signatures for ActivityPub in PHP

· 2 comments · 900 words · Viewed ~1,475 times


A padlock engraved into a circuit board.

If you're reading this, you've probably been hitting your head against a brick wall trying to parse and decipher the new HTTP Signatures sent by Mastodon and other Fediverse servers. This is a basic and somewhat incomplete guide to accepting these signatures. I'm sure there are various gotchas, but it works with the signatures I've seen in the wild. Shut Up And Show Me The Code! OK, wow, no…

Auth0 PHP - manually authenticating JWT idTokens

· 1 comment · 500 words · Viewed ~2,109 times


Auth0 logo. It looks very boring and corporate.

I find it baffling just how poorly documented most big projects are. Auth0 by Okta has a fair bit of cash, lots of customers, and almost completely absent documentation. Here's how to successfully authenticate a JWT supplied by Auth0. Once your user has authenticated with Auth0, they will be given an accessToken and an idToken. Only the idToken is needed for our purposes. It will look…

PHP - simple way to send HTTP headers before a script ends

· 1 comment · 50 words · Viewed ~2,617 times


The PHP logo.

Suppose you want PHP to keep processing after it has sent back an HTTP response. Normally, this doesn't work: <?php header( "Location: https://example.com/" ); // Long operation. sleep(10); die(); Try it yourself. You'll have to wait 10 seconds before you get back < HTTP/2 302 < location: https://example.com/ There are some complex ways to fix this - they usually involve…

Vertically Aligning Roman Numerals in Code

· 1 comment · 200 words · Viewed ~2,752 times


The PHP logo.

I have a PHP function which uses Roman Numerals. It looks like this: $romanNumerals = [ "Ⅿ" => 1000, "ⅭⅯ" => 900, "Ⅾ" => 500, "ⅭⅮ" => 400, "Ⅽ" => 100, "ⅩC" => 90, "Ⅼ" => 50, "ⅩⅬ" => 40, "Ⅹ" => 10, "Ⅸ" => 9, "Ⅷ" => 8, "Ⅶ" => 7, "Ⅵ" => 6, "Ⅴ" => 5, "Ⅳ" => 4, "Ⅲ" => 3, "Ⅱ" => 2, "Ⅰ" => 1 ]; The problem is, the…

You can parse an .env file as an .ini with PHP - but there's a catch

· 1 comment · 500 words · Viewed ~2,362 times


The PHP logo.

The humble .env file is a useful and low-tech way of storing persistent environment variables. Drop the file on your server and let your PHP scripts consume it with glee. But consume it how? There are lots of excellent parsing libraries for PHP. But isn't there a simpler way? Yes! You can use PHP's parse_ini_file() function and it works. But… .env and .ini have subtly different behaviour which …

Some updates to ActivityBot

· 1 comment · 1,150 words · Viewed ~756 times


Logo for ActivityPub.

I couple of years ago, I developed ActivityBot - the simplest way to build Mastodon Bots. It is a single PHP file which can run an entire ActivityPub server and it is less than 80KB. It works! You can follow @openbenches to see the latest entries on OpenBenches.org, and @colours for a slice of colour in your day, and @solar to see…

A big list of things I disable in WordPress

· 14 comments · 900 words · Viewed ~4,739 times


The Logo for WordPress.

There are many things I like about the WordPress blogging software, and many things I find irritating. The most annoying aspect is that WordPress insists that its way is the best and there shall be no deviance. That means a lot of forced cruft being injected into my site. Headers that bloat my page size, Gutenberg stuff I've no use for, and ridiculous editorial decisions. To double-down on the…

A Self-Hosted Favicon Proxy written in PHP

· 3 comments · 600 words · Viewed ~575 times


The PHP logo.

In theory, you should be able to get the base favicon of any domain by calling /favicon.ico - but the reality is somewhat more complex than that. Plenty of sites use a wide variety of semi-standardised images which are usually only discoverable from the site's HTML. There are several services which allow you to get favicons based on a domain. But they all have their problems. Google Exposes…

Stop using preg_* on HTML and start using \Dom\HTMLDocument instead

· 5 comments · 850 words · Viewed ~1,093 times


The PHP logo.

It is a truth universally acknowledged that a programmer in possession of some HTML will eventually try to parse it with a regular expression. This makes many people very angry and is widely regarded as a bad move. In the bad old days, it was somewhat understandable for a PHP coder to run a quick-and-dirty preg_replace() on a scrap of code. They probably could control the input and there wasn't …

Using Tempest Highlight with WordPress

· 1 comment · 300 words · Viewed ~319 times


The HTML5 Logo.

I like to highlight bits of code on my blog. I was using GeSHi - but it has ceased to receive updates and the colours it uses aren't WCAG compliant. After skimming through a few options, I found Tempest Highlight. It has nearly everything I want in a code highlighter:  PHP with no 3rd party dependencies.  Lots of common languages.  Modern, with regular updates.  Easy to use fun…