-
-
- Submit Updated Articles to Bing and Yandex with IndexNow in Joomla
- Add Published and Modified Date Meta Tags to Joomla
- Add Open Graph and Twitter Card Tags to Joomla
- Auto-Generate Meta Descriptions from Article Text in Joomla
- Add Noindex to Specific Pages in Joomla
- Verify Your Joomla Site with Google Search Console
-
- Add a View as Markdown Link to Joomla Articles
- Display the Last Modified Date in Joomla Articles
- Embed Iframes in Joomla
- Automatically Link Twitter (X) @mentions in Joomla Articles
- Open External Links in a New Tab in Joomla
- Display Estimated Reading Time in Joomla Articles
- Replace Old URLs in Joomla
- Search and Replace in Joomla
-
- Add a Footer Line to the Joomla Administrator
- Show a Staging Banner in the Joomla Administrator
- Remove the "All" Option from Admin List Limits in Joomla
- Add a Cookie Consent Banner to Joomla
- Make the Administrator Navigation Sticky in Joomla
- Add Google Fonts to Joomla
- Add a Facebook Messenger Chat Button to Joomla
- Add a Reading Progress Bar to Joomla
- Add a Custom Scrollbar to Joomla
- Show Confetti on a Thank You Page in Joomla
- Add Smooth Scrolling to Joomla
- Add a Back to Top Button in Joomla
- Add a WhatsApp Chat Button in Joomla
-
- Protect the Administrator with a Secret URL Key in Joomla
- Show a Welcome Message on First Login in Joomla
- Log Out Idle Administrators in Joomla
- Assign New Users to a Different User Group Automatically in Joomla
- Redirect Visitors by Country in Joomla
- Redirect Users After Login by User Group in Joomla
- Block User Registration with Certain Usernames in Joomla
- Block User Registration by Country in Joomla
- Block User Registration by Email Address in Joomla
- Block User Registration by IP Address in Joomla
- Remove the Forgot Password and Username Links in Joomla
- Remove the Generator Meta Tag in Joomla
- Let Users Log In with Their Email Address in Joomla
- Block Traffic by Country in Joomla
- Block Bot Traffic in Joomla
- Block Traffic by IP Address in Joomla
Block User Registration by IP Address in Joomla
Stop one troublemaker from creating account after account by blocking Joomla user registration from chosen IP addresses or ranges, using one PHP snippet.
The same visitor keeps creating fake accounts on your site, and every one of them means another spam profile to delete. Joomla's registration form doesn't look at where a sign-up comes from. You can block user registration from specific IP addresses in Joomla with one PHP snippet in Code Snippets.
The PHP snippet code
The snippet runs right before Joomla stores a new account. When the visitor's address is on your list, Joomla cancels the registration and shows your message on the form. Logins, profile edits and existing accounts aren't affected, and the blocked visitor can still browse the site.
use Joomla\CMS\Factory;
use Joomla\Utilities\IpHelper;
// Addresses that can't register. A full address blocks one visitor.
// A prefix that ends in a dot, like '198.51.100.', blocks the whole range.
$blockedIPs = [
'203.0.113.10',
'198.51.100.',
];
// Message shown on the registration form instead of the welcome message.
$message = 'Registration is not available from your network.';
// Do not edit below.
$app = Factory::getApplication();
$app->registerEvent('onUserBeforeSave', function ($event) use ($blockedIPs, $message)
{
// Only new accounts. Profile edits pass through.
if (!$event->getArgument('isNew', $event->getArgument(1, false)))
{
return;
}
$ip = (string) IpHelper::getIp();
foreach ($blockedIPs as $blockedIP)
{
$blockedIP = trim($blockedIP);
if ($blockedIP === '')
{
continue;
}
$isPrefix = substr($blockedIP, -1) === '.';
$matches = $isPrefix ? strpos($ip, $blockedIP) === 0 : $ip === $blockedIP;
if ($matches)
{
// Joomla cancels the registration and shows this message.
throw new RuntimeException($message);
}
}
});
Change the 2 settings at the top:
$blockedIPs: the addresses that can't register. A full address like203.0.113.10blocks that one visitor. A prefix that ends in a dot, like198.51.100., blocks every address that starts with it.$message: the text Joomla shows on the registration form. It appears after "Registration failed:".
How to add this snippet
- Install Code Snippets if it isn't installed already.
- Log into your Joomla backend.
- Go to Components → Tassos Code Snippets.
- Click New.
- Enter a title, for example Block registration by IP.
- Set Code Type to PHP.
- Set Insertion Method to Auto-Insert Locations.
- Set Location to On Page Load.
- Paste the code above into the editor.
- Replace the sample addresses with the ones you want to block.
- Click Save & Close.
Check that it works
- Add your own IP address to
$blockedIPsand save the snippet. A search for "what is my IP" shows your address. - Open your site's registration page in a private browser window and submit the form with a test name and email.
Joomla shows "Registration failed: Registration is not available from your network." and creates no account. Remove your address from the list, save, and the same form goes through.
If a blocked address still gets through
Your site may sit behind Cloudflare or another proxy. Joomla then sees the proxy's address instead of the visitor's, so the snippet compares the wrong address. Go to System → Global Configuration, open the Server tab, set Behind Load Balancer to Yes, and click Save & Close. Leave it off when there's no proxy, because it lets visitors fake their address.
To block visitors by email address, country or username, see Block User Registration by Email Address in Joomla, Block User Registration by Country in Joomla and Block User Registration with Certain Usernames in Joomla. To keep an address off the whole site, see Block Traffic by IP Address in Joomla. To learn more about how PHP snippets work, read the PHP snippet docs.