Header Ads

exec('PRAGMA journal_mode=WAL;'); // settings table $db->exec('CREATE TABLE settings (k TEXT PRIMARY KEY, v TEXT)'); // default settings $defaults = [ 'site_title' => 'My USA TV Channel', 'logo_url' => '', // optional 'channel_image' => '', // optional 'channel_name' => 'Morning News Live', 'channel_subtitle' => 'Breaking news • USA', 'affiliate_link' => 'https://example.com', 'signup_link' => '#', 'live_link' => '#', 'ad_html' => '
Your Ad Here
', 'viewers_base' => '4200', 'admin_pass_hash' => password_hash(DEFAULT_ADMIN_PASS, PASSWORD_DEFAULT), ]; $stmt = $db->prepare('INSERT INTO settings (k,v) VALUES (:k, :v)'); foreach ($defaults as $k => $v) { $stmt->bindValue(':k', $k, SQLITE3_TEXT); $stmt->bindValue(':v', $v, SQLITE3_TEXT); $stmt->execute(); } // comments table $db->exec('CREATE TABLE comments (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, text TEXT, ts INTEGER)'); // clicks log $db->exec('CREATE TABLE clicks (id INTEGER PRIMARY KEY AUTOINCREMENT, to_url TEXT, ts INTEGER)'); // contact messages $db->exec('CREATE TABLE messages (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, email TEXT, message TEXT, ts INTEGER)'); $db->close(); } // helper: get DB connection function db() { $db = new SQLite3(DB_FILE); $db->exec('PRAGMA journal_mode=WAL;'); return $db; } // helper: get setting function get_setting($k, $default = '') { $db = db(); $stmt = $db->prepare('SELECT v FROM settings WHERE k=:k'); $stmt->bindValue(':k', $k, SQLITE3_TEXT); $res = $stmt->execute()->fetchArray(SQLITE3_ASSOC); $db->close(); return $res ? $res['v'] : $default; } // helper: set setting function set_setting($k, $v) { $db = db(); $stmt = $db->prepare('REPLACE INTO settings (k,v) VALUES (:k,:v)'); $stmt->bindValue(':k',$k,SQLITE3_TEXT); $stmt->bindValue(':v',$v,SQLITE3_TEXT); $res = $stmt->execute(); $db->close(); return $res; } // --- ACTIONS: admin login, save settings, upload images, post comment, contact --- // $action = $_REQUEST['action'] ?? ''; if ($action === 'admin_login') { $pass = $_POST['password'] ?? ''; $hash = get_setting('admin_pass_hash'); if ($hash && password_verify($pass, $hash)) { $_SESSION['is_admin'] = true; header('Location: /'); exit; } else { $error = 'Wrong password'; } } if ($action === 'admin_logout') { unset($_SESSION['is_admin']); header('Location: /'); exit; } if ($action === 'save_settings' && !empty($_SESSION['is_admin'])) { // sanitize simple fields $site_title = trim($_POST['site_title'] ?? ''); $channel_name = trim($_POST['channel_name'] ?? ''); $channel_subtitle = trim($_POST['channel_subtitle'] ?? ''); $affiliate_link = trim($_POST['affiliate_link'] ?? ''); $signup_link = trim($_POST['signup_link'] ?? ''); $live_link = trim($_POST['live_link'] ?? ''); $ad_html = $_POST['ad_html'] ?? ''; $viewers_base = intval($_POST['viewers_base'] ?? 4200); set_setting('site_title', $site_title); set_setting('channel_name', $channel_name); set_setting('channel_subtitle', $channel_subtitle); set_setting('affiliate_link', $affiliate_link); set_setting('signup_link', $signup_link); set_setting('live_link', $live_link); set_setting('ad_html', $ad_html); set_setting('viewers_base', strval($viewers_base)); // upload channel image if (!empty($_FILES['channel_image']['name'])) { $f = $_FILES['channel_image']; $ok = false; $ext = strtolower(pathinfo($f['name'], PATHINFO_EXTENSION)); $allowed = ['jpg','jpeg','png','webp','gif']; if (in_array($ext, $allowed) && $f['size'] < 5 * 1024 * 1024) { $newName = 'channel_' . time() . '.' . $ext; $dst = UPLOAD_DIR . '/' . $newName; if (move_uploaded_file($f['tmp_name'], $dst)) { // store accessible path relative to site $url = 'uploads/' . $newName; set_setting('channel_image', $url); } } } // upload logo if (!empty($_FILES['logo_image']['name'])) { $f = $_FILES['logo_image']; $ext = strtolower(pathinfo($f['name'], PATHINFO_EXTENSION)); $allowed = ['jpg','jpeg','png','webp','gif','svg']; if (in_array($ext, $allowed) && $f['size'] < 2 * 1024 * 1024) { $newName = 'logo_' . time() . '.' . $ext; $dst = UPLOAD_DIR . '/' . $newName; if (move_uploaded_file($f['tmp_name'], $dst)) { $url = 'uploads/' . $newName; set_setting('logo_url', $url); } } } // change admin password if requested if (!empty($_POST['new_admin_password'])) { $newpw = $_POST['new_admin_password']; set_setting('admin_pass_hash', password_hash($newpw, PASSWORD_DEFAULT)); } header('Location: /?saved=1'); exit; } if ($action === 'post_comment') { $name = trim($_POST['c_name'] ?? 'Guest'); $text = trim($_POST['c_text'] ?? ''); if ($text !== '') { $db = db(); $stmt = $db->prepare('INSERT INTO comments (name, text, ts) VALUES (:n, :t, :ts)'); $stmt->bindValue(':n', $name, SQLITE3_TEXT); $stmt->bindValue(':t', $text, SQLITE3_TEXT); $stmt->bindValue(':ts', time(), SQLITE3_INTEGER); $stmt->execute(); $db->close(); } header('Location: /'); exit; } if ($action === 'post_message') { $name = trim($_POST['m_name'] ?? ''); $email = trim($_POST['m_email'] ?? ''); $msg = trim($_POST['m_msg'] ?? ''); if ($email && $msg) { $db = db(); $stmt = $db->prepare('INSERT INTO messages (name, email, message, ts) VALUES (:n,:e,:m,:ts)'); $stmt->bindValue(':n', $name, SQLITE3_TEXT); $stmt->bindValue(':e', $email, SQLITE3_TEXT); $stmt->bindValue(':m', $msg, SQLITE3_TEXT); $stmt->bindValue(':ts', time(), SQLITE3_INTEGER); $stmt->execute(); $db->close(); // optional: try sending email to admin using PHP mail() if configured $to = get_setting('contact_email', ''); if ($to) { $subject = "Website message from " . ($name?:$email); $body = $msg . "\n\nFrom: " . ($name?:'') . " <{$email}>"; @mail($to, $subject, $body, "From: {$email}\r\n"); } } header('Location: /?msgsent=1'); exit; } if ($action === 'log_click') { // logs an affiliate click (AJAX) $to = $_POST['to'] ?? get_setting('affiliate_link'); $db = db(); $stmt = $db->prepare('INSERT INTO clicks (to_url, ts) VALUES (:t, :ts)'); $stmt->bindValue(':t', $to, SQLITE3_TEXT); $stmt->bindValue(':ts', time(), SQLITE3_INTEGER); $stmt->execute(); $db->close(); echo json_encode(['ok'=>1]); exit; } if ($action === 'delete_comment' && !empty($_SESSION['is_admin'])) { $id = intval($_GET['id'] ?? 0); if ($id) { $db = db(); $stmt = $db->prepare('DELETE FROM comments WHERE id=:id'); $stmt->bindValue(':id', $id, SQLITE3_INTEGER); $stmt->execute(); $db->close(); } header('Location: /'); exit; } ////////// render page ////////// $site_title = htmlspecialchars(get_setting('site_title','My USA TV Channel')); $logo_url = get_setting('logo_url',''); $channel_image = get_setting('channel_image',''); if (!$channel_image) $channel_image = 'https://images.unsplash.com/photo-1502136969935-8d6f05f2f0c6?q=80&w=1400&auto=format&fit=crop'; $channel_name = htmlspecialchars(get_setting('channel_name','Morning News Live')); $channel_subtitle = htmlspecialchars(get_setting('channel_subtitle','Breaking news • USA')); $affiliate_link = htmlspecialchars(get_setting('affiliate_link','https://example.com')); $signup_link = htmlspecialchars(get_setting('signup_link','#')); $live_link = htmlspecialchars(get_setting('live_link','#')); $ad_html = get_setting('ad_html','
Your Ad
'); $viewers_base = intval(get_setting('viewers_base', 4200)); $contact_email = htmlspecialchars(get_setting('contact_email','')); $is_admin = !empty($_SESSION['is_admin']); ?> <?php echo $site_title;?>

channel
▶
Base viewers

Comments

query('SELECT id,name,text,ts FROM comments ORDER BY ts DESC LIMIT 100'); while ($r = $res->fetchArray(SQLITE3_ASSOC)) { $id = intval($r['id']); $n = htmlspecialchars($r['name']); $t = nl2br(htmlspecialchars($r['text'])); $time = date('Y-m-d H:i', intval($r['ts'])); echo "
{$n} {$time}"; echo "
{$t}
"; if ($is_admin) { echo ""; } echo "
"; } $db->close(); ?>

Contact

Messages are stored in the site. Admin can view them in the Admin panel.
© — • Admin access protected by password.

Admin Login

'.$error.'
'; endif; ?>
First time? Default admin password is . Change it after login.

Admin Panel

Current:
Current:
After saving, logout and login with the new password.

Messages

Visitor messages (sent via contact form)
query('SELECT id,name,email,message,ts FROM messages ORDER BY ts DESC LIMIT 200'); echo '
'; while ($r = $res->fetchArray(SQLITE3_ASSOC)) { $id = intval($r['id']); echo '
'; echo ''.htmlspecialchars($r['name']).' '.htmlspecialchars($r['email']).'
'; echo '
'.nl2br(htmlspecialchars($r['message'])).'
'; echo '
'; } echo '
'; $db->close(); ?>

No comments

Powered by Blogger.