On this page
Most PHP websites that get hacked are not hit by clever, one-off attacks. They fall to a small set of well-known weaknesses: SQL injection, cross-site scripting (XSS), unsafe file uploads and outdated software or plugins. The good news is that each one has a standard, proven fix, and a careful developer can close all of them without rebuilding your site.
This guide explains each attack in plain English, shows what the fix looks like, and ends with a checklist you can hand to whoever maintains your website.
Why PHP sites are a common target
PHP runs a very large share of the web, including WordPress and many custom business sites, so attackers write automated tools for it. Bots scan the internet around the clock looking for old PHP versions, known plugin flaws and forms that do not check their input. They are not choosing your business; they are trying every site they can reach.
PHP itself is not insecure. Modern PHP has everything needed to write safe code. The trouble usually comes from three places: code written years ago without security in mind, add-ons that are never updated, and servers running a PHP version that no longer receives security fixes.
The OWASP Top 10, the most widely used list of web application risks, was refreshed in its 2025 edition. Broken access control is still at number one, injection remains on the list, and a new category covers software supply chain failures, meaning the risk that comes from the third-party code and packages your site depends on. All four attacks below map directly to that list.
The four attacks that cause most of the damage
1. SQL injection
Your website talks to its database using a language called SQL. If a form field, search box or URL value is pasted straight into a database query, an attacker can type SQL commands instead of normal text. The database then runs them. The result can be a full copy of your customer table, changed prices or deleted records.
The fix: use prepared statements (also called parameterised queries) everywhere. With PHP's PDO or MySQLi, the query and the user's input are sent to the database separately, so input can never be treated as a command. This is the primary defence recommended by OWASP. Extra layers help too: give the website's database user only the permissions it needs, and never show raw database errors to visitors.
2. Cross-site scripting (XSS)
XSS happens when a site takes something a user typed, such as a comment, a name or a search term, and prints it back onto a page without cleaning it. If that text contains a script, the browser of every visitor who views the page will run it. Attackers use this to steal login sessions, show fake login boxes or redirect visitors to scam sites.
The fix: escape all output for the place it appears. In plain PHP that means wrapping user data in htmlspecialchars() before printing it into HTML; template engines do this automatically. Where you must allow some formatting, such as in a blog editor, pass the HTML through a proper sanitiser that keeps only safe tags. A Content Security Policy header adds a second line of defence by telling browsers which scripts are allowed to run.
3. Unsafe file uploads
Upload forms for CVs, profile photos or product images are a favourite entry point. If the site only checks the file name, an attacker can upload a PHP file disguised as an image. If that file lands in a folder the web server will execute, the attacker now has a "web shell": a back door that lets them run commands on your server.
The fix: check what a file really is, not what it claims to be. Good upload handling:
- allows only the specific types you need (for example JPG, PNG and PDF) and checks the file's actual content, not just its extension;
- sets a sensible size limit;
- renames every file to a random name chosen by the server;
- stores uploads outside the public web folder, or in a folder where script execution is switched off;
- serves private files, such as CVs, only through a script that checks the user is allowed to see them.
4. Outdated PHP, plugins and libraries
This is one of the most common ways small business sites are broken into, and one of the easiest to prevent. When a security flaw in a popular plugin or library is published, bots start scanning for unpatched sites within days. Running an old PHP version is just as risky: according to php.net, as of November 2026 PHP 8.1 and every older version no longer receive security fixes, and PHP 8.2 reaches the end of its security support on 31 December 2026.
The fix: keep a list of everything your site depends on (PHP version, CMS, plugins, Composer packages, JavaScript libraries) and update it on a schedule. Remove plugins you no longer use; switched-off plugins can still be attacked if their files remain on the server.
Other gaps attackers look for
Beyond the big four, a few smaller mistakes turn up again and again on business websites:
- Weak admin logins. Admin panels at predictable addresses with short passwords and no limit on login attempts are easy to brute-force. Use strong, unique passwords, limit failed attempts and add two-factor authentication where you can.
- Passwords stored in plain text. User passwords should be stored with PHP's password_hash() and checked with password_verify(), never as readable text or with old, fast hashes such as MD5.
- Exposed files. Backup files, database dumps, error logs and configuration files left in the public folder can be downloaded by anyone who guesses the name. Block them on the server and keep secrets out of version control.
- Missing access checks. An admin page that hides its menu link but does not check who is logged in is still open. Every page and API endpoint must check permissions on the server.
- Unprotected forms. Forms need rate limits and spam checks; admin forms that change data should use CSRF tokens.
A practical security checklist for your PHP website
Use this table as a starting point for a conversation with your developer or hosting provider.
| Area | What good looks like | How often |
|---|---|---|
| Database queries | All queries use prepared statements; the database user has limited rights | Every code change |
| Output | All user-supplied text is escaped; rich text passes through a sanitiser | Every code change |
| File uploads | Type checked by content, size limit, random names, no script execution in upload folders | Every code change |
| Software versions | Supported PHP version; CMS, plugins and packages up to date; unused plugins removed | Monthly |
| Admin access | Strong unique passwords, login rate limits, two-factor where possible, old accounts removed | Quarterly review |
| Secrets and files | Config, logs and backups not reachable from the web; secrets not in git | Quarterly review |
| Backups | Automatic off-server backups of files and database, with a tested restore | Daily backup, restore test quarterly |
| Monitoring | Uptime alerts, error logs reviewed, Google Search Console security alerts switched on | Ongoing |
If you are not sure where your site stands, an independent review is the fastest way to find out. Our security and code audit looks at exactly these areas and gives you a prioritised list of fixes in plain English. If the code is too old to patch safely, we can help you plan a rebuild through our web application development service, with security built in from the first sprint.
Building security into how your site is maintained
Fixing today's holes is only half the job. Sites become vulnerable again when nobody owns updates. A few habits make a big difference:
- Name an owner. Someone, in-house or your development partner, should be responsible for updates, backups and checking security alerts.
- Review code before it goes live. A second pair of eyes on every change catches unescaped output and raw queries before attackers do.
- Use a staging copy. Test updates on a copy of the site first, so you are never tempted to skip them for fear of breaking things.
- Put a web application firewall or CDN in front. Services that filter traffic can block many automated attacks and absorb traffic floods. They help, but they do not replace secure code.
- Keep logs. Server and application logs tell you what happened if something goes wrong. Indian organisations covered by CERT-In's 2022 directions must keep logs of their ICT systems for a rolling 180 days and report incidents such as website intrusions and defacement within six hours of noticing them.
At Appspine, every project is delivered in two-week sprints with a working build each sprint, and security checks are part of that routine rather than a last-minute add-on. You own the code, so whoever maintains it next can see exactly what was done. If you want a second opinion on your website, get in touch and we will sign an NDA before you share any details.
Frequently asked questions
Is PHP less secure than other languages?
No. Modern PHP has strong, built-in tools for safe database access, password hashing and output escaping. Most PHP security problems come from old code, outdated plugins and unsupported PHP versions, not from the language itself.
How do I know if my website is vulnerable to SQL injection?
The only reliable way is to review the code. If any database query is built by joining strings together with user input instead of using prepared statements, it is likely vulnerable. A code audit or a professional security test will find these spots.
Does a firewall or CDN make my site secure?
It helps by blocking many automated attacks and known bad traffic, but it cannot fix flaws in your own code. Treat a firewall as an extra layer on top of secure code, regular updates and good backups.
How often should I update plugins and PHP?
Check for updates at least monthly and apply security updates as soon as they are released, ideally after a quick test on a staging copy. Plan PHP version upgrades well before your current version reaches end of support, which php.net publishes in advance.
What should I do if I think my site has already been hacked?
Do not just delete the obvious bad files. Take a copy of the site and logs for investigation, change all passwords, find how the attacker got in, then clean or restore from a known-good backup and patch the hole. If you are covered by CERT-In's directions, report the incident within six hours of noticing it.
Sources
Written by the Appspine team
We are an app and software development company in Noida, India, with 200+ projects delivered and apps live on the App Store and Google Play. Rated 4.5★ on Clutch and 5.0★ on Google.
Free consultation
Turn this idea into your app
Share a few details. We will call or WhatsApp you with a clear plan and free estimate. No spam, no obligation.