From 6597535f60f30806c3534d62ea1cf19349411002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hi=E1=BA=BFu=20Star?= <66201416+huzely@users.noreply.github.com> Date: Mon, 29 Dec 2025 16:50:32 +0700 Subject: [PATCH] Prevent duplicate session start warnings --- public_html/.htaccess | 6 ++ public_html/README.md | 35 +++++++ public_html/admin/dashboard.php | 27 ++++++ public_html/admin/includes/auth_check.php | 4 + public_html/admin/includes/footer.php | 4 + public_html/admin/includes/header.php | 23 +++++ public_html/admin/login.php | 45 +++++++++ public_html/admin/logout.php | 6 ++ public_html/admin/post_add.php | 74 ++++++++++++++ public_html/admin/post_copy.php | 32 ++++++ public_html/admin/post_delete.php | 12 +++ public_html/admin/post_edit.php | 80 +++++++++++++++ public_html/admin/posts.php | 62 ++++++++++++ public_html/admin/settings.php | 113 ++++++++++++++++++++++ public_html/admin/stats.php | 78 +++++++++++++++ public_html/api/stats.php | 8 ++ public_html/api/track.php | 38 ++++++++ public_html/assets/css/admin.css | 16 +++ public_html/assets/css/base.css | 43 ++++++++ public_html/assets/css/theme1.css | 3 + public_html/assets/css/theme2.css | 4 + public_html/assets/css/theme3.css | 4 + public_html/assets/js/adflow.js | 38 ++++++++ public_html/assets/js/app.js | 15 +++ public_html/assets/js/track.js | 16 +++ public_html/bots/telegram/webhook.php | 11 +++ public_html/config.php | 16 +++ public_html/error.php | 19 ++++ public_html/includes/footer.php | 6 ++ public_html/includes/header.php | 38 ++++++++ public_html/includes/menu.php | 13 +++ public_html/index.php | 78 +++++++++++++++ public_html/lib/auth.php | 41 ++++++++ public_html/lib/cache.php | 31 ++++++ public_html/lib/csrf.php | 15 +++ public_html/lib/db.php | 19 ++++ public_html/lib/error_handler.php | 38 ++++++++ public_html/lib/helpers.php | 42 ++++++++ public_html/lib/rate_limit.php | 34 +++++++ public_html/lib/slugify.php | 9 ++ public_html/lib/telegram.php | 63 ++++++++++++ public_html/logs/app.log | 0 public_html/post.php | 79 +++++++++++++++ public_html/sql/database.sql | 67 +++++++++++++ 44 files changed, 1405 insertions(+) create mode 100644 public_html/.htaccess create mode 100644 public_html/README.md create mode 100644 public_html/admin/dashboard.php create mode 100644 public_html/admin/includes/auth_check.php create mode 100644 public_html/admin/includes/footer.php create mode 100644 public_html/admin/includes/header.php create mode 100644 public_html/admin/login.php create mode 100644 public_html/admin/logout.php create mode 100644 public_html/admin/post_add.php create mode 100644 public_html/admin/post_copy.php create mode 100644 public_html/admin/post_delete.php create mode 100644 public_html/admin/post_edit.php create mode 100644 public_html/admin/posts.php create mode 100644 public_html/admin/settings.php create mode 100644 public_html/admin/stats.php create mode 100644 public_html/api/stats.php create mode 100644 public_html/api/track.php create mode 100644 public_html/assets/css/admin.css create mode 100644 public_html/assets/css/base.css create mode 100644 public_html/assets/css/theme1.css create mode 100644 public_html/assets/css/theme2.css create mode 100644 public_html/assets/css/theme3.css create mode 100644 public_html/assets/js/adflow.js create mode 100644 public_html/assets/js/app.js create mode 100644 public_html/assets/js/track.js create mode 100644 public_html/bots/telegram/webhook.php create mode 100644 public_html/config.php create mode 100644 public_html/error.php create mode 100644 public_html/includes/footer.php create mode 100644 public_html/includes/header.php create mode 100644 public_html/includes/menu.php create mode 100644 public_html/index.php create mode 100644 public_html/lib/auth.php create mode 100644 public_html/lib/cache.php create mode 100644 public_html/lib/csrf.php create mode 100644 public_html/lib/db.php create mode 100644 public_html/lib/error_handler.php create mode 100644 public_html/lib/helpers.php create mode 100644 public_html/lib/rate_limit.php create mode 100644 public_html/lib/slugify.php create mode 100644 public_html/lib/telegram.php create mode 100644 public_html/logs/app.log create mode 100644 public_html/post.php create mode 100644 public_html/sql/database.sql diff --git a/public_html/.htaccess b/public_html/.htaccess new file mode 100644 index 0000000..bf55d4c --- /dev/null +++ b/public_html/.htaccess @@ -0,0 +1,6 @@ +RewriteEngine On +RewriteCond %{REQUEST_URI} !^/(admin|api|bots|assets|includes|lib|cache|logs)/ +RewriteCond %{REQUEST_FILENAME} !-f +RewriteRule ^([A-Za-z0-9-]+)/?$ post.php?slug=$1 [L,QSA] + +RewriteRule ^$ index.php [L] diff --git a/public_html/README.md b/public_html/README.md new file mode 100644 index 0000000..c29f778 --- /dev/null +++ b/public_html/README.md @@ -0,0 +1,35 @@ +# Báo tin tức PHP thuần + +Triển khai cho hosting share (PHP 7.4, MySQL) với ba theme, quản trị tiếng Việt và flow quảng cáo Shopee không delay, giữ link affiliate s.shopee.vn. + +## Cách cài đặt +1. Upload toàn bộ thư mục `public_html` lên hosting (dataonline.vn hoặc tương tự). +2. Import MySQL file `sql/database.sql` (đã seed admin: `admin / admin567`). +3. Sửa file `public_html/config.php` với thông tin DB, `BASE_URL`, token Telegram, `APP_DEBUG`. +4. Đảm bảo file `.htaccess` hoạt động để rewrite slug: `/slug` -> `post.php?slug=...`. +5. Phân quyền ghi cho thư mục `cache/` và `logs/`. + +## Đăng nhập admin +- URL: `/admin/login.php` +- Tài khoản mặc định: **admin / admin567** (mật khẩu đã được hash trong DB). + +## Kiểm tra nhanh sau khi deploy +- **Quảng cáo Shopee**: Bật quảng cáo ở `Admin > Cài đặt`, nhập link s.shopee.vn. Truy cập bài viết: overlay xuất hiện, bấm bất kỳ nơi nào hoặc nút X sẽ mở bài ở tab mới với `?ad=0` và tab hiện tại đi Shopee (không delay). Truy cập trực tiếp `/slug` vẫn thấy overlay trừ khi URL có `?ad=0`. +- **Theme**: Vào `Admin > Cài đặt`, đổi giữa Theme 1/2/3, toàn site đổi màu ngay. +- **Chống click ảo**: Tracking dùng token phiên + rate limit IP/UA/slug (30s) trong `/api/track.php`; spam gọi API sẽ nhận `rate_limited`. +- **Log lỗi**: Khi `APP_DEBUG=false`, lỗi được ghi vào `logs/app.log` và hiển thị `error.php` thân thiện (không trắng trang). + +## Thư mục chính +- `index.php`: trang chủ, phân trang, menu 3D, trigger quảng cáo trên click bài. +- `post.php`: trang bài, meta SEO/OG, hiển thị media Telegram, overlay quảng cáo nếu bật. +- `assets/css`: `base.css` + `theme1/2/3.css` + `admin.css`. +- `assets/js`: `app.js` (UI + menu), `adflow.js` (overlay Shopee đúng flow), `track.js` (tracking không chậm redirect). +- `admin/`: đăng nhập, CRUD bài, copy link, cài đặt, thống kê (view/ngày/tháng/ad click, reset). +- `api/track.php`: nhận tracking page/post/ad với rate limit và token, gộp thông báo Telegram. +- `lib/`: PDO, auth, cache file, csrf, slugify, rate-limit, telegram, helpers, error handler. + +## Lưu ý vận hành +- Ảnh/logo/banner được lưu trong `assets/img/` (nhẹ, phù hợp share hosting). +- Cache file cho trang chủ/bài ~45s; cài đặt cache 5 phút. +- Không sử dụng framework hay CLI/composer. +- Gửi Telegram: cấu hình token/chat_id trong `config.php`; hàng đợi + gộp click trong `telegram_queue` và `telegram_notifications`. diff --git a/public_html/admin/dashboard.php b/public_html/admin/dashboard.php new file mode 100644 index 0000000..e367db5 --- /dev/null +++ b/public_html/admin/dashboard.php @@ -0,0 +1,27 @@ +query("SELECT COUNT(*) FROM articles")->fetchColumn(); +$publicArticles = (int)$pdo->query("SELECT COUNT(*) FROM articles WHERE status='public'")->fetchColumn(); +$views = (int)$pdo->query("SELECT COUNT(*) FROM events WHERE event_type='post_view'")->fetchColumn(); +$adClicks = (int)$pdo->query("SELECT COUNT(*) FROM events WHERE event_type='ad_click'")->fetchColumn(); +include __DIR__ . '/includes/header.php'; +?> +
+