Код:
<html>
<body>
<!-- 12345 -->
<?php
// Written by XeroXer at XeroXer.com. Credz to Major_Meatbone and tcp for helping me solve the admin area problem and and the storing of entrys. :)
// You may use this script freely on any site you wish.
// --------------------------------------------------
// EDIT SETTINGS FOR YOUR GUESTBOOK!
// --------------------------------------------------
$gbfile = "guestbook.txt"; // The file that all guestbook entrys should be saved in.
$dateshow = "Y-m-d - H:i:s"; // Decides how the date should be shown. http://www.w3schools.com/php/func_date_date.asp
$username = "user"; // Admin username.
$password = "pass"; // Admin password.
$notlog = "Not logged in!"; // Text to show when the user enters wrong username or password.
$thankstxt = "Thank you for writing in my guestbook!"; // The text that the user will see after entering something in the guestbook.
$errorrequire = "Required fields are name and message!"; // Text the user will see if the requested fields was not entered.
$gbedited = "Guestbook has been edited!"; // Text to print out when guestbook has been edited.
$nogbedited = "No entrys selected to be removed!"; // Text to print out when no entrys where selected for removal.
$smsgstart = "<meta http-equiv=\"refresh\" content=\"3;URL=?id=\" /><p>"; // Start of every message printed out.
$smsgend = "<br />You will be sent back in 3 seconds. If not click <a href=\"?id=\">here</a></p>"; // End of every message printed out.
// --------------------------------------------------
// NO EDIT NEEDED BELOW THIS LINE!
// --------------------------------------------------
$arr = file($gbfile);
$mdpass = md5($password);
$date = date($dateshow);
$name = htmlentities(strip_tags($_POST['name']));
$email = htmlentities(strip_tags($_POST['email']));
if($_POST['homepage'] == "" || $_POST['homepage'] == "http://") {
$homepage = "";
} else {
$homepage = htmlentities(strip_tags($_POST['homepage']));
}
$message = nl2br(htmlentities(strip_tags($_POST['message'])));
$message = str_replace(array("\r", "\n"), '', $message);
$message = wordwrap($message, 75, "<br />", true);
$name = str_replace(';', '.-_.-_', $name);
$email = str_replace(';', '.-_.-_', $email);
$homepage = str_replace(';', '.-_.-_', $homepage);
$message = str_replace(';', '.-_.-_', $message);
$writeinfo = "{$date};{$name};{$email};{$homepage};{$message}\n";
switch($_GET['id'])
{
// DEFAULT GUESTBOOK PAGE
default:
echo "<p align=\"left\"><a href=\"?id=login\">Admin</a></p>\n";
echo "<table align=\"center\"><form action=\"?id=write\" method=\"post\" name=\"submitform\">\n";
echo "<tr><td><strong>Name: *</strong></td><td><input type=\"text\" name=\"name\" size=\"40\" maxlength=\"50\" /></td></tr>\n";
echo "<tr><td><strong>Email:</strong></td><td><input type=\"text\" name=\"email\" size=\"40\" maxlength=\"50\" /></td></tr>\n";
echo "<tr><td><strong>Homepage:</strong></td><td><input type=\"text\" name=\"homepage\" size=\"40\" maxlength=\"50\" value=\"http://\" /></td></tr>\n";
echo "<tr><td valign=\"top\"><strong>Message: *</strong></td><td><textarea name=\"message\" cols=\"30\" rows=\"7\"></textarea></td></tr>\n";
echo "<tr><td></td><td><input type=\"submit\" name=\"submit\" value=\"Submit\" /></td></tr>\n";
echo "</form></table><br />\n\n";
$gb = file($gbfile);
$gb = array_reverse($gb);
foreach ($gb as $guestbook) {
$gastbok = stripslashes($guestbook);
list($datum, $namn, $epost, $hemsida, $meddelande) = split(';', $gastbok);
$namn = str_replace('.-_.-_',';',$namn);
$epost = str_replace('.-_.-_',';',$epost);
$hemsida = str_replace('.-_.-_',';',$hemsida);
$meddelande = str_replace('.-_.-_',';',$meddelande);
echo "<table width=\"400\" border=\"1\" align=\"center\">\n";
echo "<tr><td width=\"80\"><strong>Date:</strong></td><td width=\"320\">{$datum}</td></tr>\n";
echo "<tr><td><strong>Name:</strong></td><td>".($epost == "" ? "" : "<a href=\"mailto:{$epost}\">")."{$namn}".($epost == "" ? "" : "</a>")."</td></tr>\n";
if(!$hemsida) {
echo "";
} else {
echo "<tr><td><strong>Homepage:</strong></td><td><a href=\"{$hemsida}\" target=\"_blank\">{$hemsida}</a></td></tr>\n";
}
echo "<tr><td><strong>Message:</strong></td><td>{$meddelande}</td></tr>\n";
echo "</table><br />\n\n";
}
break;
// WRITE ENTRYS TO FILE
case write:
if($name == "" || $message == "") {
echo "{$smsgstart}{$errorrequire}{$smsgend}";
} else {
$printer = fopen($gbfile, 'a');
fwrite($printer,$writeinfo);
fclose($printer);
echo "{$smsgstart}{$thankstxt}{$smsgend}";
}
break;
// LOGIN TO ADMIN SECTION
case login:
echo "<p align=\"left\"><a href=\"?id=\">Back</a></p>\n";
echo "<table align=\"center\"><form action=\"?id=admin\" method=\"post\" name=\"submitform\">\n";
echo "<tr><td><strong>Username:</strong></td><td><input type=\"text\" name=\"adminname\" size=\"20\" /></td></tr>\n";
echo "<tr><td><strong>Password:</strong></td><td><input type=\"password\" name=\"adminpass\" size=\"20\" /></td></tr>\n";
echo "<tr><td></td><td><input type=\"submit\" name=\"submit\" value=\"Login\" /></td></tr>\n";
echo "</form></table>\n";
break;
// LISTING ALL ENTRYS FOR REMOVING
case admin:
if($_POST["adminname"] == $username && $_POST["adminpass"] == $password) {
$verpass = md5($_POST['adminpass']);
echo "<p align=\"left\"><a href=\"?id=\">Back</a></p>\n";
echo "<table align=\"center\">\n";
echo "<form action=?id=delete method=POST>\n";
echo "<tr><td>\n";
foreach ($arr as $line_num => $line) {
echo "<input type=checkbox name=delete[] value={$line_num} />[D] <b>Entry #{$line_num}</b>:\n";
list($datum, $namn, $epost, $hemsida, $meddelande) = split(';', $line);
$namn = str_replace('.-_.-_',';',$namn);
$epost = str_replace('.-_.-_',';',$epost);
$hemsida = str_replace('.-_.-_',';',$hemsida);
$meddelande = str_replace('.-_.-_',';',$meddelande);
echo "<table width=\"400\" border=\"1\" align=\"center\">\n";
echo "<tr><td width=\"80\"><strong>Date:</strong></td><td width=\"320\">{$datum}</td</tr>\n";
echo "<tr><td><strong>Name:</strong></td><td>".($epost == "" ? "" : "<a href=\"mailto:{$epost}\">")."{$namn}".($epost == "" ? "" : "</a>")."</td></tr>\n";
if(!$hemsida) {
echo "";
} else {
echo "<tr><td><strong>Homepage:</strong></td><td><a href=\"{$hemsida}\" target=\"_blank\">{$hemsida}</a></td></tr>\n";
}
echo "<tr><td><strong>Message:</strong></td><td>{$meddelande}</td></tr>\n";
echo "</table><br />\n\n";
}
echo "</td></tr>\n<tr><td>\n";
echo "<input type=\"hidden\" name=\"psw\" value=\"{$verpass}\" />\n";
echo "<input type=submit value=remove />\n</form>\n";
echo "</td></tr></table>\n";
} else {
echo "{$smsgstart}{$notlog}{$smsgend}";
}
break;
// DELETING SELECTED POSTS
case delete:
if($_POST["psw"] == $mdpass) {
if($_POST['delete'] != "") {
foreach($_POST['delete'] as $key => $val) {
unset($arr[$val]);
// >> PHP VERSION CHECK AND FUNCTIONS
$pversion = phpversion();
$version = $pversion{0};
if($version == "5") {
file_put_contents($gbfile, join("", $arr));
} else {
$handle = fopen($gbfile, 'w');
fwrite($handle, join("", $arr));
fclose($handle);
}
// << PHP VERSION CHECK AND FUNCTIONS
}
echo "{$smsgstart}{$gbedited}{$smsgend}";
} else {
echo "{$smsgstart}{$nogbedited}{$smsgend}";
}
} else {
echo "{$smsgstart}{$notlog}{$smsgend}";
}
break;
}
?>
<!-- 54321 -->
</body>
</html>