PHP security checklist: 15 controls every business app needs
Most breaches of business websites do not use clever zero-day exploits. They use old, well-known weaknesses: unpatched software, weak passwords, leaked keys and unsafe input. This checklist turns the OWASP Top 10 into 15 controls that owners can ask about and developers can verify, with short PHP code examples.
TL;DR
- Most real incidents come from basics: outdated software, SQL injection, weak authentication, exposed secrets and missing access checks.
- Ask your team for evidence of 15 controls: patching, prepared statements, output escaping, CSRF protection, password hashing, safe sessions, upload checks, secrets management, security headers, dependency audits, logging, backups, least privilege and more.
- Most controls are cheap if built in from the start and expensive to retrofit after an incident.
- Security is a process: automate checks in CI, review access quarterly and rehearse your response to a breach.
- Customers and partners in the US increasingly ask for a security questionnaire before they sign. Having these controls documented shortens that conversation.
If you sell to other businesses, sooner or later a customer sends you a security questionnaire. If you handle payments or personal data, regulators and card networks have expectations too. And if you are simply running a website that makes money, an attacker does not care how small you are, because automated scanners look at every site. This PHP security checklist is written for owners and managers who need to ask the right questions, and for developers who need a concrete list.
It is not a replacement for a penetration test or a formal compliance program such as SOC 2 or PCI DSS. It covers the controls that prevent the most common incidents. The structure follows the OWASP Top 10, the standard reference list of web application risks.
Part 1: keep the foundations current
1. Run a supported PHP version and patched dependencies
Old PHP versions stop receiving security fixes. The same applies to your framework, CMS, plugins and libraries. This is the most common root cause we see in audits. See our PHP 8 upgrade guide for how to plan the move. Make dependency checks routine:
# known vulnerabilities in your Composer dependencies
composer audit
# what is outdated (direct dependencies only)
composer outdated --direct
# in CI, fail the build when a known vulnerability is found
composer audit --locked --abandoned=report
2. Never trust input: use prepared statements
SQL injection is still among the most damaging flaws. The fix is simple and has been available for many years: never build queries by concatenating user input.
// Vulnerable: input becomes part of the SQL
$rows = $pdo->query("SELECT * FROM orders WHERE email = '" . $_GET['email'] . "'");
// Safe: the database treats input as data only
$stmt = $pdo->prepare('SELECT * FROM orders WHERE email = :email');
$stmt->execute(['email' => $_GET['email'] ?? '']);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
Make sure PDO is configured with exceptions on and emulated prepares off (PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false), and that the database user has only the permissions the application needs.
3. Escape output to stop cross-site scripting (XSS)
Anything a user can type can end up in a page. Escape it for the context where it is displayed:
function e(?string $s): string {
return htmlspecialchars($s ?? '', ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}
echo '<h1>Hello, ' . e($user['name']) . '</h1>';
Template engines such as Twig and Blade escape by default. Raw HTML output should be rare, reviewed and sanitized with a proper library.
Part 2: identity and access
4. Store passwords with a modern hash
Never store passwords in plain text or with fast hashes like MD5 or SHA-1. PHP has the right tools built in:
$hash = password_hash($password, PASSWORD_DEFAULT); // store this
if (password_verify($input, $hash)) {
if (password_needs_rehash($hash, PASSWORD_DEFAULT)) {
$hash = password_hash($input, PASSWORD_DEFAULT); // upgrade silently on login
}
// log the user in
}
5. Require multi-factor authentication for admins and staff
Stolen or reused passwords are a leading cause of account takeover. Enable multi-factor authentication on the admin panel, hosting, DNS, source repository, email and payment dashboards. Use authenticator apps or hardware keys, not only SMS.
6. Check authorization on every request
Being logged in is not the same as being allowed. A very common flaw is a user who changes an ID in the URL and sees another customer's invoice. For every object, check that the current user owns it or has a role that permits it. Test this explicitly with two different accounts.
7. Harden sessions and add CSRF protection
session_set_cookie_params([
'lifetime' => 0,
'path' => '/',
'secure' => true, // only over HTTPS
'httponly' => true, // not readable by JavaScript
'samesite' => 'Lax',
]);
session_start();
session_regenerate_id(true); // after login, to prevent session fixation
// CSRF token for every state-changing form
$_SESSION['csrf'] ??= bin2hex(random_bytes(32));
// ... include it in the form, then verify:
if (!hash_equals($_SESSION['csrf'], $_POST['csrf'] ?? '')) {
http_response_code(403); exit;
}
Part 3: data, files and secrets
8. Validate and restrict file uploads
Uploads are a classic way to get code onto your server. Check the real type, limit size, generate your own file names and store files outside the web root or on object storage so they can never be executed:
$f = $_FILES['doc'] ?? null;
if (!$f || $f['error'] !== UPLOAD_ERR_OK || $f['size'] > 5 * 1024 * 1024) { exit('Invalid file'); }
$mime = (new finfo(FILEINFO_MIME_TYPE))->file($f['tmp_name']);
$allowed = ['application/pdf' => 'pdf', 'image/jpeg' => 'jpg', 'image/png' => 'png'];
if (!isset($allowed[$mime])) { exit('Type not allowed'); }
$name = bin2hex(random_bytes(16)) . '.' . $allowed[$mime]; // never use the original name
move_uploaded_file($f['tmp_name'], '/var/app-uploads/' . $name); // outside the web root
9. Keep secrets out of code and out of Git
API keys, database passwords and signing secrets belong in environment variables or a secrets manager, never in the repository. Add a scanner to CI such as gitleaks, rotate any key that was ever committed, and use separate keys for development and production. Verify webhook signatures from payment providers, as shown in our Stripe webhooks guide.
10. Encrypt in transit and at rest
Force HTTPS everywhere, with HSTS. Encrypt backups. Encrypt sensitive fields such as tokens or personal identifiers when the risk warrants it. Do not store payment card numbers yourself: let a payment processor handle them, which also reduces your PCI DSS scope.
11. Collect and keep only the data you need
Data you do not store cannot leak. Define retention periods, delete old records and be ready to answer data access and deletion requests under rules such as GDPR and CCPA if you have customers in those regions.
Part 4: the server and the surrounding system
12. Add security headers and a safe server configuration
# Nginx
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Content-Security-Policy "default-src 'self'; img-src 'self' data: https:; frame-ancestors 'self'" always;
server_tokens off;
location ~ /\.(?!well-known) { deny all; } # no .env, .git and similar
location ~* \.(sql|bak|log|ini)$ { deny all; }
In php.ini for production set display_errors=0, expose_php=0 and log errors to a file. A public error page that shows a stack trace is a gift to attackers.
13. Apply least privilege everywhere
The web application should connect to the database with a dedicated user that cannot drop tables. Staff should have only the access their role needs. Remove accounts of people who left, the same day. Review access to hosting, repositories and third-party tools every quarter.
14. Log security events and watch them
Log logins, failed logins, password resets, permission changes and administrative actions with time, user and IP. Alert on spikes of failures. Do not log passwords, card data or full tokens. Pair this with the monitoring approach in our backup and monitoring guide.
15. Prepare for the day it happens
Have tested backups, a short incident plan (who decides, who talks to customers, who rotates keys), and a way to take the site offline fast. Know in advance which laws require you to notify customers or authorities after a breach, as rules differ by US state and by country.
How to use this list
- Give it to your developer or agency and ask for a short written answer for each of the 15 points: yes, no, or not applicable, with the evidence.
- Fix the "no" answers in this order: patching, authentication, injection, access control, secrets.
- Automate what you can: dependency audit, secret scanning and static analysis in CI.
- Re-run the review every quarter and after major changes. For an older codebase, start with our legacy code audit checklist to see how much work you are facing.
How we can help
We review PHP applications, fix security issues and build integrations, including payment and API integrations, with these controls in place from day one. Read about our integrations service or book a call and we will go through your application against this checklist.
Frequently asked questions
What are the most common security problems in PHP applications?
Outdated PHP versions and dependencies, SQL injection from unsafe queries, cross-site scripting from unescaped output, weak password storage, missing authorization checks, exposed secrets and unrestricted file uploads. Most are prevented by a small set of well-known controls.
How do I prevent SQL injection in PHP?
Use prepared statements with bound parameters through PDO or your framework's query builder, and never concatenate user input into SQL. Also give the application's database user only the permissions it needs.
How should passwords be stored in PHP?
Use password_hash() with PASSWORD_DEFAULT and check with password_verify(). Never use MD5, SHA-1 or plain text. Add multi-factor authentication for admin and staff accounts.
Do I need a penetration test?
A checklist and automated scans catch common problems, but a penetration test by an independent expert finds issues in your specific logic and is often requested by enterprise customers. Fix the basics first so the test is not spent on easy findings.
How often should we review our application security?
Patch continuously, run automated dependency and secret scans on every change, and do a deeper review every quarter and after major releases or incidents.
Free discovery call
Bring a messy stack or stalled integration - Integrono will map the smartest first move.
You get a senior take on budget traps, dependencies and whether to buy, glue or build - before paid work starts. The CEO stays in the loop.