Open-Gemini-Chatbot-Php

agent
Guvenlik Denetimi
Uyari
Health Uyari
  • License — License: NOASSERTION
  • Description — Repository has a description
  • Active repo — Last push 0 days ago
  • Low visibility — Only 5 GitHub stars
Code Uyari
  • network request — Outbound network request in script.js
Permissions Gecti
  • Permissions — No dangerous permissions requested
Purpose
This project is a self-hosted, lightweight PHP chatbot interface designed to connect to Google's Gemini API. It includes a frontend UI with file upload capabilities, markdown rendering, and multi-layer security features like rate limiting and CSRF protection.

Security Assessment
Overall Risk: Medium. The tool acts as an API wrapper, meaning it handles sensitive credentials. You must configure your own Gemini API keys and Supabase service role keys in a `.env` file. Provided you manage these secrets properly and do not commit them to public version control, the risk is contained. The code does not request dangerous system permissions or execute local shell commands. Outbound network requests are expected and documented, as the frontend JavaScript needs to communicate with the backend PHP scripts to reach the external AI API. Security measures against XSS and CORS are explicitly built into the codebase, which is a positive sign.

Quality Assessment
The project appears to be actively maintained, with repository activity as recent as today. However, visibility and community trust are currently very low, indicated by only 5 GitHub stars. It lacks a formally recognized open-source license (marked as NOASSERTION), which means legal usage and modification rights are technically undefined. Additionally, the documentation appears to be primarily written in Turkish, which may be a barrier for some international developers.

Verdict
Use with caution. The security features are well-documented, but the low community adoption and lack of a clear license mean you should thoroughly review the codebase yourself before deploying it in a production environment.
SUMMARY

Secure, lightweight, and modern PHP-based Google Gemini AI chatbot. Features advanced security measures (CSRF, Rate Limiting, CORS) and file upload support.

README.md

Gemini AI Chatbot (PHP)

A secure, self-hosted AI chatbot powered by Google's Gemini API. Built with PHP, vanilla JavaScript, and CSS — no frameworks required. Features real-time typing effects, markdown rendering, code syntax highlighting, file uploads, dark/light theme, and multi-layer security.


Demo: https://ai.arvasin.com.tr/

Ekran görüntüsü 2026-04-12 135920

Türkçe

Özellikler

  • Çok katmanlı güvenlik: CSRF token, Origin/Referer kontrolü, IP bazlı rate limiting
  • Koyu/Açık tema desteği
  • Yazma efekti ile gerçekçi bot yanıtları
  • Markdown desteği: Başlıklar, listeler, tablolar, kod blokları
  • Kod sözdizimi vurgulaması (Highlight.js)
  • Dosya yükleme: Resim, PDF, TXT, CSV
  • XSS koruması (DOMPurify)
  • Mobil uyumlu (responsive) tasarım
  • Hafif: Hiçbir framework gerektirmez

Kurulum

  1. Dosyaları sunucunuza yükleyin (PHP 8.3+ önerilir, curl eklentisi aktif olmalı)

  1. .env dosyasını oluşturup düzenleyin — API ve Veritabanı bilgilerinizi girin:
    GEMINI_API_KEY="BURAYA_API_ANAHTARINIZI_GİRİN"
    SUPABASE_URL="BURAYA_SUPABASE_URL_GİRİN"
    SUPABASE_ANON_KEY="BURAYA_SUPABASE_ANON_KEY_GİRİN"
    SUPABASE_SERVICE_ROLE_KEY="BURAYA_SUPABASE_SERVICE_ROLE_KEY_GİRİN"
    

    API anahtarınızı Google AI Studio adresinden alabilirsiniz.


  1. api.php dosyasını düzenleyin:
    • session_set_cookie_params (Satır 22 civarı): .yourdomain.com kısmını kendi alan adınıza göre uyarlayın.
    • $allowed_origins (Satır 34 civarı): İzin verilen origin alan adlarını kendi domain adınızla değiştirin.
    • $valid_referers (Satır 120 civarı): Referer doğrulaması için geçerli sayfalarınızı güncelleyin.
    • systemInstruction (Satır 383 civarı): Yapay zekaya özel kişisel komutlarınızı yazın.

  1. auth.php dosyasını düzenleyin (Giriş/Kayıt işlemleri için):
    • session_set_cookie_params (Satır 6 civarı): .yourdomain.com kısmını güncelleyin.
    • $redirect_to (Satır 34 civarı): Başarılı işlemlerden sonra yönlendirme yapılacak URL'i güncelleyin.
    • $allowed_origins (Satır 47 civarı): İzin verilen origin alan adlarını kendi domain adınızla değiştirin.

  1. index.php dosyasını düzenleyin:
    • session_set_cookie_params (Satır 6 civarı): Çerezler için .yourdomain.com kısmını güncelleyin.
    • Sayfa başlığını, SEO etiketlerini, karşılama metnini ve giriş ekranı ayarlarını isteğinize göre değiştirin.

  1. .htaccess (Satır 58 ve 67 civarı) dosyasını düzenleyin:
    • İlgili satırlardaki yourdomain\.com kısımlarını kendi domain adınızla değiştirin (noktaları \. şeklinde escape etmeyi unutmayın):
      RewriteCond %{HTTP_REFERER} !^https?://(www\.)?sizindomain\.com [NC]
      

  1. Görselleri değiştirin (isteğe bağlı):
    • logo.png — Bot avatarı ve favicon
    • kullanici.png — Kullanıcı avatarı

Dosya Yapısı

Dosya Açıklama
.env Çevresel değişkenler (API anahtarı ve Supabase bağlantı bilgileri)
config.php Çevresel değişken okuyucu yardımcı fonksiyonları
auth.php Kullanıcı kimlik doğrulama işlemleri (Giriş, Kayıt, Supabase OAuth entegrasyonu)
api.php Backend API proxy'si — güvenlik katmanları + Gemini API iletişimi
index.php Ana sayfa — PHP oturum başlatma + HTML arayüz
script.js Frontend mantığı — sohbet, dosya yükleme, tema
style.css Tüm stiller — koyu/açık tema, markdown, responsive
.htaccess Apache güvenlik kuralları
.user.ini PHP güvenlik ayarları
logo.png Bot avatarı / Favicon
kullanici.png Kullanıcı avatarı


English

Features

  • Multi-layer security: CSRF token, Origin/Referer check, IP-based rate limiting
  • Dark/Light theme toggle
  • Typing effect for realistic bot responses
  • Markdown support: Headings, lists, tables, code blocks
  • Code syntax highlighting (Highlight.js)
  • File upload: Images, PDF, TXT, CSV
  • XSS protection (DOMPurify)
  • Mobile-friendly (responsive) design
  • Lightweight: No frameworks required

Setup

  1. Upload files to your server (PHP 7.4+ required, curl extension must be enabled)

  1. Create and edit the .env file — Enter your API keys and Database info:
    GEMINI_API_KEY="YOUR_GEMINI_API_KEY_HERE"
    SUPABASE_URL="YOUR_SUPABASE_URL_HERE"
    SUPABASE_ANON_KEY="YOUR_SUPABASE_ANON_KEY_HERE"
    SUPABASE_SERVICE_ROLE_KEY="YOUR_SUPABASE_SERVICE_ROLE_KEY_HERE"
    

    Get your Gemini API key from Google AI Studio.


  1. Edit api.php:
    • session_set_cookie_params (Around Line 22): Update the .yourdomain.com cookie domain.
    • $allowed_origins (Around Line 34): Replace the array values with your actual domains for CORS.
    • $valid_referers (Around Line 120): Replace array values with your actual domain.
    • systemInstruction (Around Line 383): Customize the system instruction to define your AI's personality.

  1. Edit auth.php (For authentication):
    • session_set_cookie_params (Around Line 6): Update the .yourdomain.com cookie domain.
    • $redirect_to (Around Line 34): Update the redirect URL to match your domain.
    • $allowed_origins (Around Line 47): Update the allowed origin domains.

  1. Edit index.php:
    • session_set_cookie_params (Around Line 6): Update the .yourdomain.com cookie domain.
    • Customize the page details, SEO metadata, initial messages, and functionality as needed.

  1. Edit .htaccess (Lines 58 and 67 approx):
    • Replace yourdomain\.com with your actual domain (escape dots with \.):
      RewriteCond %{HTTP_REFERER} !^https?://(www\.)?yourdomain\.com [NC]
      

  1. Replace images (optional):
    • logo.png — Bot avatar and favicon
    • kullanici.png — User avatar

File Structure

File Description
.env Environment variables (API Key and Supabase connections)
config.php Helper functions to load .env variables
auth.php User authentication endpoints (Login, Signup, Supabase integration)
api.php Backend API proxy — security layers + Gemini API communication
index.php Main page — PHP session init + HTML interface
script.js Frontend logic — chat, file upload, theme
style.css All styles — dark/light theme, markdown, responsive
.htaccess Apache security rules
.user.ini PHP security settings
logo.png Bot avatar / Favicon
kullanici.png User avatar


Security Architecture

User Request
    │
    ├── .htaccess ──── HTTPS redirect, Referer check, Sensitive file blocking (.env, .php)
    │
    ├── api.php
    │   ├── Origin check (CORS) with Preflight support
    │   ├── CSRF token & user session validation
    │   ├── Referer check (2nd layer)
    │   ├── IP based rate limiting (Atomic file locks, Cloudflare IP resolution)
    │   ├── POST-only enforcement & JSON payload validation
    │   ├── Strict payload sanitization & structural check
    │   └── Supabase logging & Gemini API communication
    │
    └── config.php ──── Local environment variable reader (.env)

Available Gemini Models

Model Description
gemini-3.1-flash-lite-preview Fast, cost-effective preview
gemini-2.0-flash Fast and efficient (stable recommended)
gemini-2.5-pro-preview-05-06 Most capable, preview
gemini-2.5-flash-preview-04-17 Latest flash preview

See the full list at Google AI Models.


License

This project is licensed under the MIT License — see the LICENSE file for details.

Original Author: ahmettkahraman


Contributing

Contributions, issues, and feature requests are welcome! Feel free to open an issue or submit a pull request.

Yorumlar (0)

Sonuc bulunamadi