FAUSTINE June 29, 2025 1 min read

"Jinsi ya Kuhariri Tangazo la Tovuti kwa PHP Bila Kuingia Kwenye cPanel (Hatua kwa Hatua)"

🔹 1. Unda Faili iitwayo edit_tangazo.php
👉 Hii ndiyo sehemu ya blog ambayo itakuwa na form ya kuhariri na kuhifadhi tangazo.

📜 Code Kamili:
php
Copy
Edit
<?php
// Nenosiri la kuingia
$password = "TANGAZO"; // Badilisha nenosiri lako hapa

// Form ya kuingiza nenosiri
if (!isset($_POST['password']) && !isset($_POST['new_message'])) {
echo '<form method="post"><h3>🔒 Ingiza Nenosiri:</h3><input type="password" name="password" required /><br><br><button type="submit">Ingia</button></form>';
exit;
}

// Cheki kama nenosiri ni sahihi
if (isset($_POST['password']) && $_POST['password'] !== $password) {
die("❌ Nenosiri si sahihi.");
}

// Kuhifadhi tangazo jipya
if (isset($_POST['new_message'])) {
file_put_contents("tangazo.txt", trim($_POST['new_message']));
$success = "✅ Tangazo limehifadhiwa kikamilifu!";
}

// Soma tangazo la sasa
$current = file_exists("tangazo.txt") ? file_get_contents("tangazo.txt") : "";
?>

<!DOCTYPE html>
<html lang="sw">
<head>
<meta charset="UTF-8">
<title>Hariri Tangazo</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; background-color: #f1f1f1; }
form { background: white; padding: 20px; border-radius: 10px; max-width: 600px; margin: auto; box-shadow: 0 0 10px rgba(0,0,0,0.1); }
textarea { width: 100%; height: 150px; font-size: 1rem; padding: 10px; border-radius: 5px; border: 1px solid #ccc; }
button { padding: 10px 20px; background: #007bff; color: #fff; border: none; border-radius: 5px; cursor: pointer; }
button:hover { background: #0056b3; }
.success { color: green; font-weight: bold; margin-top: 10px; }
</style>
</head>
<body>

<h2 style="text-align:center;">📢 Hariri Tangazo Linalotembea</h2>

<?php if (isset($success)): ?>
<p class="success"><?= $success ?></p>
<?php endif; ?>

<form method="post">
<label>Andika Tangazo Lako Hapa:</label><br>
<textarea name="new_message"><?= htmlspecialchars($current) ?></textarea><br><br>
<input type="hidden" name="password" value="<?= htmlspecialchars($_POST['password']) ?>" />
<button type="submit">💾 Hifadhi Tangazo</button>
</form>

</body>
</html>
🔹 2. Unda au Hakikisha Faili tangazo.txt Ipo
Katika folder moja na edit_tangazo.php, tengeneza faili tangazo.txt

Iweke wazi au uandike tangazo la mwanzo.

Mfano:

nginx
Copy
Edit
Karibu kwenye Faulink.com - Tovuti ya Mifumo ya Elimu, Biashara na Teknolojia!
🔹 3. Tumia Fomu ya Web Kuhariri
Tembelea ukurasa: https://yourdomain.com/edit_tangazo.php

Ingiza nenosiri: TANGAZO (au uliloweka)

Jaza tangazo jipya na bonyeza 💾 Hifadhi Tangazo

Litaandikwa ndani ya tangazo.txt

🔹 4. Mahali pa Kuonyesha Tangazo
Katika sehemu yoyote ya frontend ya blog yako (k.m. index.php), ongeza hii:

php
Copy
Edit
<?php
$tangazoText = file_exists('tangazo.txt') ? trim(file_get_contents('tangazo.txt')) : '';
?>

<?php if (!empty($tangazoText)): ?>
<div class="scrolling-announcement">
<span><?= htmlspecialchars($tangazoText) ?></span>
</div>
<?php endif; ?>
Na kwenye <style>:

css
Copy
Edit
.scrolling-announcement {
background: #ffc107;
color: #000;
font-weight: 700;
font-size: 1.1rem;
overflow: hidden;
white-space: nowrap;
box-sizing: border-box;
padding: 10px 0;
margin: 20px 0;
}

.scrolling-announcement span {
display: inline-block;
padding-left: 100%;
animation: scroll-left 15s linear infinite;
}

.scrolling-announcement:hover span {
animation-play-state: paused;
}

@keyframes scroll-left {
0% { transform: translateX(0%); }
100% { transform: translateX(-100%); }
}

🚀 Unahitaji mfumo au website ya biashara?

Chagua huduma hapa chini kisha mteja bofya moja kwa moja kwenda kwenye ukurasa wa huduma au kuwasiliana nasi kwa WhatsApp.

Share this post

Comments

0
No comments yet. Be the first to comment.

Continue Reading

Subscribe

Get new updates

Jiunge upokee posts mpya, tutorials, na updates za mifumo moja kwa moja kwenye email yako.

Faulink Support