Добавяне на новини
add.php
<?php

if (!isset($_POST['news'])) {

?>

<h1>Add to the News Page</h1>
<table>
<FORM action="add.php" method="POST">
<tr>
<td align=right>Title:</td>
<td><INPUT TYPE="TEXT" name="title"></td>
</tr>
<tr>
<td align=right valign=top>News:</td>
<td><TEXTAREA WRAP=VIRTUAL NAME="news" COLS=50 ROWS=15></TEXTAREA></td>
</tr>
<tr>
<td></td>
<td><INPUT TYPE="SUBMIT" name="submit" value="Submit"></td>
</tr>
</FORM>
</table>

<?php

} else {

$da = getdate();
$date="$da[weekday] $da[mday] $da[month] $da[year]";
$news=$HTTP_POST_VARS['news'];
$title=$HTTP_POST_VARS['title'];
$news = ("$title|$date|$news\n");

$file = fopen("news.php", "r");
$read = fread($file, filesize("news.php"));
fclose($file);
$newsfile = fopen("news.php", "w");
$news=stripslashes($news);
fwrite($newsfile, "$news$read");
fclose ($newsfile);

echo "News added";

}

?>


delete.php
<?php

$posts = file("news.php");

if (!isset($_GET['delete'])) {

echo "<h1>Delete a News Post</h1>";

$i = 0;
while ($i <= count($posts)-1) {
$tempnews = (explode('|', $posts[$i], 3));
echo "<hr><p><b>$tempnews[0]</b> - $tempnews[1]</p><p>$tempnews[2]</p>";
echo "<a href=\"delete.php?delete=$i\">Delete the above post</a></p>";
$i++;
}

} else {

$todelete = $_GET['delete'];

$posts[$todelete]="";
$finishedoutput = implode("", $posts);

$blah = fopen("news.php", "w");
fwrite($blah, "$finishedoutput");
fclose ($blah);

echo "<h1>News post removed</h1>";

echo "$posts[$todelete]";
echo "<p><a href=\"delete.php\">Click here to delete another</a></p>";

}

?>


allnews.php
<?php

echo "<h1>All News</h1>";

$allnews = file("news.php");
$i = 0;
while ($i <= count($allnews)-1) {
$tempnews = (explode('|', $allnews[$i], 3));
echo "<hr><p><b>$tempnews[0]</b> - $tempnews[1]</p><p>$tempnews[2]</p>";
$i++;
}
echo "<hr>";

?>


latest.php
<?php

echo "<h1>Latest News</h1>";

$allnews = file("news.php");
$i = 0;
while ($i <= 2) {

$tempnews = (explode('|', $allnews[$i], 3));

if ($tempnews[1] != "") {
echo "<hr><p><b>$tempnews[0]</b> - $tempnews[1]</p><p>$tempnews[2]</p>";
}

$i++;
}

echo "<hr>";
echo "<p><a href=\"allnews.php\">View All News</a></p>";

?>






/ Трябва да сте регистриран за да напишете коментар /
От: reletobg
0:27 19-02-2010
Пускай кат ще пускаш всичко!
1