DEMO: https://rasmus6992.com/randomaistuff/cvtohtmlv1/
A self-contained PHP 8 portal that accepts raw CV text, generates a modern Tailwind portfolio with the OpenAI Responses API, previews it inside a sandboxed iframe, synchronizes light/dark mode, and downloads the final portfolio as a standalone HTML file.
- OOP PHP 8 architecture with no third-party PHP package dependency
- PDO/MySQL with native prepared statements
- Concurrency-safe IP rate limiting using an InnoDB transaction and
SELECT ... FOR UPDATE - Three accepted generation attempts per IP, followed by an absolute one-hour cooldown
- IPv4 and IPv6 support using packed
VARBINARY(16)values - Trusted-proxy-aware IP resolution; forwarding headers are ignored by default
- CSRF protection, strict input validation, request-size limits, and safe error responses
- OpenAI Responses API integration using server-side cURL
- Prompt-injection resistance: CV text is explicitly handled as untrusted data
- Server-side HTML allowlist sanitization
- Sandboxed iframe preview without same-origin access
- Synchronized application/preview dark mode
- Desktop/mobile preview widths
- Copy and download complete standalone HTML source
- Audit metrics without storing the user's CV text
- PHP 8.1 or newer
- MySQL 8.0+ or MariaDB 10.6+
- PHP extensions:
pdo_mysql,curl,dom,mbstring,json,openssl - Apache with
mod_rewrite, or Nginx/PHP-FPM - An OpenAI API key
cv-to-html-portfolio-hub/
├── app/
│ ├── Config/Database.php
│ ├── Exceptions/RateLimitException.php
│ ├── Http/JsonResponse.php
│ ├── Security/
│ │ ├── ClientIp.php
│ │ ├── Csrf.php
│ │ └── HtmlSanitizer.php
│ ├── Services/
│ │ ├── OpenAIClient.php
│ │ ├── PortfolioGenerator.php
│ │ ├── RateLimiter.php
│ │ ├── RateLimitResult.php
│ │ └── RequestLogger.php
│ └── Support/Env.php
├── bootstrap/app.php
├── config/app.php
├── database/schema.sql
├── public/
│ ├── api/generate.php
│ ├── assets/app.js
│ ├── .htaccess
│ └── index.php
├── storage/logs/
├── .env.example
├── .htaccess
└── README.md
-
Extract the project to:
C:\xampp\htdocs\cv-to-html-portfolio-hub -
Create a database named
cv_portfolio_hubin phpMyAdmin. -
Import:
database/schema.sql -
Copy
.env.exampleto.envand update the database credentials and OpenAI key:DB_DATABASE=cv_portfolio_hub DB_USERNAME=root DB_PASSWORD= OPENAI_API_KEY=sk-your-real-key OPENAI_MODEL=gpt-4.1
-
Verify these extensions are enabled in
C:\xampp\php\php.ini:extension=curl extension=pdo_mysql extension=mbstring extension=dom
-
Restart Apache and open:
http://localhost/cv-to-html-portfolio-hub/
No Composer installation or vendor folder is required.
The recommended web root is the project's public/ directory. This keeps .env, database files, source classes, and logs outside the public document root.
For Apache shared hosting where changing the document root is impossible, the root .htaccess blocks internal directories and rewrites public requests into public/. Confirm that AllowOverride All and mod_rewrite are enabled.
For Nginx, point the server root to /path/to/cv-to-html-portfolio-hub/public and pass PHP files to PHP-FPM. Do not expose the project root directly.
Use HTTPS in production. Keep APP_DEBUG=false, restrict .env permissions, and never put the OpenAI key in JavaScript.
The application uses REMOTE_ADDR unless the direct connection comes from a proxy listed in TRUSTED_PROXIES. This prevents clients from bypassing limits by spoofing X-Forwarded-For.
Example for a private load balancer:
TRUSTED_PROXIES=10.0.0.0/8,192.168.50.10
Configure only proxy addresses or CIDR ranges you control. For Cloudflare, use the current official Cloudflare proxy ranges rather than trusting all sources.
The rate limiter reserves an attempt before calling OpenAI:
- First accepted request: count becomes 1; two attempts remain.
- Second accepted request: count becomes 2; one attempt remains.
- Third accepted request: count becomes 3; the generation is allowed and
cooldown_untilis set to database UTC time plus one hour. - Any further request during that hour receives HTTP
429and aRetry-Afterheader. - The first request after expiry atomically resets the cycle and becomes attempt 1.
Every accepted submission counts as a try, including a submission for which the upstream AI request later fails. This protects API spend and prevents repeated upstream-failure abuse.
Stores one locked rate-limit state row per packed IP address. The unique IP index and row-level transaction lock prevent simultaneous requests from exceeding three attempts.
Stores operational metrics such as status, model, duration, and error code. Raw CV text and generated HTML are deliberately not stored.
To inspect rate-limit state:
SELECT INET6_NTOA(ip_address) AS ip, request_count, cooldown_until, last_request_at FROM ip_rate_limits ORDER BY updated_at DESC;
To manually reset one IP:
UPDATE ip_rate_limits SET request_count = 0, cooldown_until = NULL, window_started_at = UTC_TIMESTAMP(6), updated_at = UTC_TIMESTAMP(6) WHERE ip_address = INET6_ATON('203.0.113.10');
app/Services/OpenAIClient.php calls:
POST https://api.openai.com/v1/responses
The API key remains server-side. The system instruction requires:
- only a raw
<main>...</main>HTML fragment - no Markdown fences or explanatory text
- standard Tailwind utility classes only
- complete
dark:variants - no scripts, styles, forms, images, SVG, external resources, or invented CV facts
- instructions embedded in CV content to be ignored
The response is still sanitized server-side; prompt instructions are never treated as the only security boundary.
The AI fragment passes through an HTML element/attribute allowlist. Unsafe tags, inline event handlers, inline styles, scripts, forms, embeds, iframes, SVG, arbitrary Tailwind values, unsafe URLs, and unknown attributes are removed.
The preview uses:
<iframe sandbox="allow-scripts">
allow-same-origin is intentionally omitted. Scripts are allowed only because the trusted preview wrapper loads the Tailwind CDN; AI-returned scripts are stripped before rendering.
The downloaded file includes a small trusted theme-toggle script and Tailwind CDN setup. For a high-traffic production service, consider compiling and self-hosting a fixed Tailwind stylesheet instead of using the browser CDN compiler.
Set the model alias in .env:
OPENAI_MODEL=gpt-4.1
The code uses the Responses API and reads either the flattened output_text field or the nested output content as a defensive fallback.
Check .env, verify MySQL is running, and confirm the database user can access cv_portfolio_hub.
Enable/install the PHP DOM/XML extension and restart the web server.
Enable/install the PHP cURL extension and restart the web server.
Confirm the browser/server Content Security Policy allows https://cdn.tailwindcss.com and that outbound access to the CDN is available.
Your app is behind a proxy. Add only that trusted proxy's address/range to TRUSTED_PROXIES; do not blindly trust forwarded headers.
- Replace IP-only limiting with authenticated account limits plus IP/device risk signals.
- Add CAPTCHA or bot detection before expensive generations.
- Queue OpenAI jobs and apply account-level spend caps.
- Compile Tailwind CSS and host it locally.
- Add centralized structured logs and alerting.
- Add automated retention cleanup for metrics tables.
- Apply database least-privilege credentials.
The generator is instructed to produce a premium, continuous one-page portfolio rather than a plain resume layout. The final downloaded HTML includes Tailwind CDN styling, dark/light mode, scroll-reveal motion, a reading-progress indicator, generated section navigation, smooth anchor scrolling, and a back-to-top control. AI markup remains server-side sanitized; interactive behavior is added by the trusted application wrapper.