From b2ceb2f1fbe2ddd48790def648da2e2cd9df4dc0 Mon Sep 17 00:00:00 2001 From: ssbg04 Date: Fri, 5 Jun 2026 23:28:31 +0800 Subject: [PATCH] fix: HTTP 500 - add missing DB includes to sub-pages, fix env reads, add cURL guards --- api/chat.php | 15 +++++++++++---- blog.php | 1 + certifications.php | 1 + projects.php | 1 + send_contact.php | 9 +++++++-- views/chatbot.php | 2 +- 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/api/chat.php b/api/chat.php index 6637e05..1846b8b 100644 --- a/api/chat.php +++ b/api/chat.php @@ -1,9 +1,9 @@ 'API Key configuration is missing. Please configure GEMINI_API_KEY in your .env file.']); @@ -166,6 +166,13 @@ $requestPayload = [ ] ]; +// Guard: cURL must be available +if (!function_exists('curl_init')) { + http_response_code(503); + echo json_encode(['error' => 'cURL is not available on this server. Please use the client-side fallback.']); + exit; +} + // Call Gemini API via cURL $url = "https://generativelanguage.googleapis.com/v1/models/gemini-3.5-flash:generateContent?key=" . urlencode($apiKey); diff --git a/blog.php b/blog.php index e45b30d..2e5f5ce 100755 --- a/blog.php +++ b/blog.php @@ -1,3 +1,4 @@ + diff --git a/certifications.php b/certifications.php index 2967830..3e92d0c 100755 --- a/certifications.php +++ b/certifications.php @@ -1,3 +1,4 @@ + diff --git a/projects.php b/projects.php index 6781863..314ecb1 100755 --- a/projects.php +++ b/projects.php @@ -1,3 +1,4 @@ + diff --git a/send_contact.php b/send_contact.php index 38e6f4f..15890ad 100644 --- a/send_contact.php +++ b/send_contact.php @@ -20,7 +20,7 @@ if ($_SERVER['REQUEST_METHOD'] !== 'POST') { } $clientIp = getClientIp(); -$rateLimit = intval(getenv('RATE_LIMIT') ?: ($_ENV['RATE_LIMIT'] ?? 10)); +$rateLimit = intval($_ENV['RATE_LIMIT'] ?? getenv('RATE_LIMIT') ?? 10); // Query submissions count from this IP address in the last hour $stmt = $mysqli->prepare("SELECT COUNT(*) as count FROM email_submissions WHERE ip_address = ? AND submitted_at >= NOW() - INTERVAL 1 HOUR"); @@ -48,9 +48,14 @@ if ($logStmt) { } // Forward submission to FormSubmit via cURL -$contactEmail = getenv('CONTACT_EMAIL') ?: ($_ENV['CONTACT_EMAIL'] ?? 'crischarlesgarcia345@gmail.com'); +$contactEmail = $_ENV['CONTACT_EMAIL'] ?? getenv('CONTACT_EMAIL') ?? 'crischarlesgarcia345@gmail.com'; $url = "https://formsubmit.co/" . $contactEmail; +if (!function_exists('curl_init')) { + header("Location: index.php?status=error&msg=cURL is not available on this server.#contact"); + exit(); +} + $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); diff --git a/views/chatbot.php b/views/chatbot.php index 33bbb7f..adb8db5 100644 --- a/views/chatbot.php +++ b/views/chatbot.php @@ -80,7 +80,7 @@ $systemPrompt .= "3. If asked about contact options or hiring, point them to his $systemPrompt .= "4. Do not make up facts or external projects not listed in the context. If you don't know the answer, politely invite the user to contact Cris directly.\n"; $systemPrompt .= "5. Format your output using simple markdown (like bolding or bullet points) to make it readable.\n"; -$apiKey = getenv('GEMINI_API_KEY') ?: ($_ENV['GEMINI_API_KEY'] ?? ''); +$apiKey = $_ENV['GEMINI_API_KEY'] ?? getenv('GEMINI_API_KEY') ?? ''; ?>