* More scripts can be found at http://jope.psykoosi.org/ (Finnish site)
*
* This is a simple guestbook built on flatfile system so there is no
* need for SQL database.
*
* Guestbook is very easy to use; just include this page into some of
* your pages and it will automatically work.
*
* This guestbook could be optimized a little. For example when I
* read data into array from datafile:
* $data = Unserialize(Implode("", File($datafile))); ->
* $data = Unserialize(File_Get_Contents($datafile));
*
* This is because file_get_contents() is pretty new function and
* everyone doesn't have it so you can edit the script by yourself.
*
* Usage (Right way to use this guestbook):
*
*
*
*
My guestbook
*
*
*
*
*
*
*/
// File where guestbooks data is saved. (no need to change this)
$datafile = "guestbook.dat";
// Do NOT edit unless you know what you're doing!
$Qstring = preg_replace("/&?act=(write|save|read)/i", "", $_SERVER["QUERY_STRING"]);
$address = ($Qstring == "") ? "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"] : "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"] . "?" . $Qstring;
if ($_GET["act"] == "write") {
echo "
Kirjoita vieraskirjaan!
";
if ($_GET["error"] == 1) {
echo "Täytä vähintään nimi ja viesti!\n";
}
if ($Qstring == "") {
echo "";
}
else if ($_GET["act"] == "save") {
if (!file_exists($datafile)) {
if (!@touch($datafile)) {
die ("Couldn't create datafile!");
}
if (!@chmod($datafile, 0777)) {
die ("Couldn't chmod datafile!");
}
}
if ($_POST["nimi"] != "" AND $_POST["viesti"] != "") {
$data = Unserialize(Implode("", File($datafile)));
$bbcode = ($_POST["bbcode"] == "disabled") ? "disabled" : "enabled";
$data[] = Array(
"nimi" => $_POST["nimi"],
"kotisivut" => $_POST["kotisivut"],
"email" => $_POST["email"],
"viesti" => $_POST["viesti"],
"aika" => time(),
"bbcode" => $bbcode
);
$fp = @fopen($datafile, "w");
if ($fp) {
fwrite ($fp, Serialize($data));
fclose ($fp);
if ($Qstring == "") {
Header ("Location: $address?act=read");
} else {
Header ("Location: $address&act=read");
}
} else {
die ("Couldn't open datafile!");
}
} else {
if ($Qstring == "") {
Header ("Location: $address?act=write&error=1");
} else {
Header ("Location: $address&act=write&error=1");
}
}
}
else if ($_GET["act"] == "read") {
if (file_exists($datafile)) {
$data = Unserialize(Implode("", File($datafile)));
if (sizeof($data) > 0 AND Is_Array($data)) {
echo "