By MD Fozla Rabbi, SEO Specialist
Three in the morning. A small panel owner in Bogura calls me. Not a client, just a friend of a friend. "Bhai, 2,000 new accounts signed up tonight. None of them are real."
Bots. Obviously. They hit his signup form, then his login form, then his password reset form. His shared hosting choked. Real customers couldn't log in. His email provider flagged him for sending thousands of verification emails.
He didn't need a fancy firewall. He needed a rate limiter. About 60 lines of PHP and one MySQL table.
This post is that rate limiter. Written for small sites on cheap hosting, the kind most Bangladeshi startups actually run on. No Redis required.
What we're protecting
The usual targets on any small web app with accounts:
- Signup — fake accounts, spam, wasted verification emails
- Login — credential stuffing (bots trying leaked email/password combos)
- Password reset — email bombing a real user, or burning your mail quota
- Contact and ticket forms — plain old spam
- Any endpoint that costs you money — SMS OTP, paid API calls, emails
If an endpoint triggers an email, an SMS or a database write, it needs a limit. Full stop.
The idea: a fixed window counter
There are fancier algorithms. Token bucket. Sliding log. Sliding window. For a small site, a fixed window is honestly enough.
How it works:
- Pick a key, like
login:ip:103.x.x.xorreset:email:someone@mail.com - Pick a window, like 15 minutes
- Count hits for that key inside the current window
- If the count passes the limit, reject the request
Simple to reason about. Simple to debug at 3 AM. That second part matters more than people admit.
The table
CREATE TABLE rate_limits ( rl_key VARCHAR(191) NOT NULL, window_start INT UNSIGNED NOT NULL, hits INT UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (rl_key, window_start) ) ENGINE=InnoDB; VARCHAR(191) because of the old utf8mb4 index length limit on some shared hosts. Annoying. But safe.
The PHP function
One atomic query does the counting. No race conditions, no "read then write" gap.
<?php function rate_limit(PDO $db, string $key, int $limit, int $windowSec): bool { $now = time(); $windowStart = $now - ($now % $windowSec); $stmt = $db->prepare( "INSERT INTO rate_limits (rl_key, window_start, hits) VALUES (:k, :w, 1) ON DUPLICATE KEY UPDATE hits = hits + 1" ); $stmt->execute([':k' => $key, ':w' => $windowStart]); $stmt = $db->prepare( "SELECT hits FROM rate_limits WHERE rl_key = :k AND window_start = :w" ); $stmt->execute([':k' => $key, ':w' => $windowStart]); $hits = (int) $stmt->fetchColumn(); return $hits <= $limit; // true = allowed } INSERT ... ON DUPLICATE KEY UPDATE is the trick. Two requests arriving at the same moment both get counted correctly. MySQL handles the locking.
Using it on login
Limit by IP and by account. Bots rotate IPs. They also hammer one account from many IPs. You want both.
<?php $ip = client_ip(); $email = strtolower(trim($_POST['email'] ?? '')); $okIp = rate_limit($db, "login:ip:$ip", 20, 900); // 20 per 15 min per IP $okEmail = rate_limit($db, "login:em:" . sha1($email), 8, 900); // 8 per 15 min per account if (!$okIp || !$okEmail) { http_response_code(429); header('Retry-After: 900'); exit('Too many attempts. Please wait 15 minutes and try again.'); } // ...normal password check continues Two notes. First, I hash the email in the key so raw emails don't sit in the rate table. Small privacy win. Second, the message tells the human what to do. "Error 429" means nothing to a shop owner on a phone.
Getting the real IP (the part that bites everyone)
Behind Cloudflare or a host's proxy, $_SERVER['REMOTE_ADDR'] is the proxy, not the visitor. Every user looks like the same IP. Then your limiter blocks everyone at once. Fun Friday night.
<?php function client_ip(): string { // Only trust this header if your site is actually behind Cloudflare if (!empty($_SERVER['HTTP_CF_CONNECTING_IP'])) { return $_SERVER['HTTP_CF_CONNECTING_IP']; } return $_SERVER['REMOTE_ADDR'] ?? '0.0.0.0'; } Don't trust X-Forwarded-For blindly. Anyone can send that header. Only trust headers set by a proxy you control.
One more local wrinkle. Mobile carriers in Bangladesh put lots of users behind shared IPs (carrier-grade NAT). A strict per-IP limit can block a whole neighborhood on the same network. Keep per-IP limits generous and lean harder on per-account limits.
Limits I actually use
Starting points. Tune them with your own logs:
- Login: 20 per IP / 15 min, 8 per account / 15 min
- Signup: 5 per IP / hour
- Password reset: 3 per email / hour, 10 per IP / hour
- Contact or ticket form: 5 per IP / 10 min
- OTP or SMS send: 3 per phone number / 15 min (SMS costs real taka)
Cleaning up old rows
The table grows forever unless you prune it. A daily cron is enough:
DELETE FROM rate_limits WHERE window_start < UNIX_TIMESTAMP() - 86400; On shared hosting, use cPanel's cron feature. Takes two minutes to set up. People skip it and then wonder why the table has four million rows.
Why this matters for panel owners specifically
Small social media service sites are bot magnets. Free signup bonuses attract fake accounts. Public pricing pages attract scrapers. Login forms attract credential stuffing.
If you're launching an SMM Panel Bangladesh business, put this in before launch, not after the first attack. It's much easier to loosen a limit later than to clean up a few thousand junk accounts.
I'd also look at how established sites structure their account flows. Open the SMM reseller panel catalog on a site like SMMBooster BD and you'll notice the boring basics: a clear signup, a protected login, an API that needs a key. Boring is good. Boring means it works.
What this doesn't solve
Being honest here:
- A distributed botnet with thousands of IPs can still get through per-IP limits. Per-account limits help. A CAPTCHA on signup helps more.
- Fixed windows allow a small burst at the window edge (up to 2x the limit for a moment). For login protection that's acceptable. For billing actions, use a stricter method.
- Rate limits don't stop a single patient attacker. Strong passwords and 2FA for admin accounts still matter.
- This isn't DDoS protection. If you're getting flooded at the network level, that's a job for Cloudflare or your host.
A tiny admin view
Last trick. Add a page that shows the top keys hitting limits in the past hour:
SELECT rl_key, SUM(hits) AS total FROM rate_limits WHERE window_start > UNIX_TIMESTAMP() - 3600 GROUP BY rl_key ORDER BY total DESC LIMIT 20; My friend in Bogura checks this every morning with his tea. He can see attacks coming before customers complain. That's the whole point.
Recap
- One table, one atomic
INSERT ... ON DUPLICATE KEY UPDATE - Limit by IP and by account
- Get the real client IP right, especially behind Cloudflare
- Keep per-IP limits generous because of shared mobile IPs
- Return 429 with a human-readable message
- Prune old rows daily
- Add it before launch, not after the first bot wave
Running a small site and want to see what a clean, simple public catalog looks like? Have a look at https://smmbooster.bd
Questions or a better limit config? Comments are open. I read them all.

