Open-Gemini-Chatbot-Php
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
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.
Secure, lightweight, and modern PHP-based Google Gemini AI chatbot. Features advanced security measures (CSRF, Rate Limiting, CORS) and file upload support.
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/
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
- Dosyaları sunucunuza yükleyin (PHP 8.3+ önerilir,
curleklentisi aktif olmalı)
.envdosyası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.
api.phpdosyasını düzenleyin:session_set_cookie_params(Satır 22 civarı):.yourdomain.comkı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.
auth.phpdosyasını düzenleyin (Giriş/Kayıt işlemleri için):session_set_cookie_params(Satır 6 civarı):.yourdomain.comkı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.
index.phpdosyasını düzenleyin:session_set_cookie_params(Satır 6 civarı): Çerezler için.yourdomain.comkı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.
.htaccess(Satır 58 ve 67 civarı) dosyasını düzenleyin:- İlgili satırlardaki
yourdomain\.comkı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]
- İlgili satırlardaki
- Görselleri değiştirin (isteğe bağlı):
logo.png— Bot avatarı ve faviconkullanici.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
- Upload files to your server (PHP 7.4+ required,
curlextension must be enabled)
- Create and edit the
.envfile — 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.
- Edit
api.php:session_set_cookie_params(Around Line 22): Update the.yourdomain.comcookie 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.
- Edit
auth.php(For authentication):session_set_cookie_params(Around Line 6): Update the.yourdomain.comcookie domain.$redirect_to(Around Line 34): Update the redirect URL to match your domain.$allowed_origins(Around Line 47): Update the allowed origin domains.
- Edit
index.php:session_set_cookie_params(Around Line 6): Update the.yourdomain.comcookie domain.- Customize the page details, SEO metadata, initial messages, and functionality as needed.
- Edit
.htaccess(Lines 58 and 67 approx):- Replace
yourdomain\.comwith your actual domain (escape dots with\.):RewriteCond %{HTTP_REFERER} !^https?://(www\.)?yourdomain\.com [NC]
- Replace
- Replace images (optional):
logo.png— Bot avatar and faviconkullanici.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)
Yorum birakmak icin giris yap.
Yorum birakSonuc bulunamadi