Her er et PHP script til en gæstebog!
Husk t lave en fil der hedder gb.txt og chmode den til 777
PHP script:
<?
// Direkte url til at læse eller skrive i GB'en
// LÆS:
http://www.dinside.dk/GB.php3?read// SKRIV:
http://www.dinside.dk/GB.php3?write//
// Du skal chmode gb.txt 777
?>
<html>
<head>
<title>Gæstebog</title>
</head>
<body>
<p align="center">
<small><font face="Verdana">Gæstebog:</font></small>
<?
echo "<font face=\"Verdana\"><small><p align=\"center\"><a href=\"".basename($PHP_SELF)."?action=write\">Skriv i gæstebogen</a><br>\n";
echo "<a href=\"".basename($PHP_SELF)."?action=read\">Læs i gæstebogen</a></small></font>\n";
?>
<?
$side = "gb.php3";
$filnavn= "gb.txt";
if ($action == "write") {
print "<hr>";
print "<FORM action=\"".basename($PHP_SELF). "\" method=\"post\">\n";
print "<TABLE WIDTH=\"100%\">\n";
print "<INPUT TYPE=\"hidden\" NAME=\"action\" VALUE=\"skriv\">\n";
print "<TR><TD>(*) skal udfyldes \n";
print "<TR><TD>Overskrift<TD><INPUT TYPE=\"text\" NAME=\"overskrift\" SIZE=\"40\">\n";
print "<TR><TD>Navn<TD><INPUT TYPE=\"text\" NAME=\"navn\" SIZE=\"40\"> * \n";
print "<TR><TD>E-mail<TD><INPUT TYPE=\"text\" NAME=\"mail\" SIZE=\"40\"> * \n";
print "<TR><TD>Hjemmeside (Uden HTTP://) <TD><INPUT TYPE=\"text\" NAME=\"url\" SIZE=\"40\">\n";
print "<TR><TD>Kommentar:<TD><TEXTAREA NAME=\"indhold\" COLS=\"40\" ROWS=\"5\"></TEXTAREA> * \n";
print "<TR><TD><TD><INPUT TYPE=\"Submit\" VALUE=\" Skriv ind \"> <INPUT TYPE=\"Reset\" VALUE=\"Fortryd\">\n";
print "<FORM>\n";
echo "</TABLE>\n";
}
if ($action == "skriv") {
if ($navn && $mail && $indhold) {
$fp = fopen($filnavn, "a");
$items = array("navn", "indhold", "url","overskrift","mail");
for ($html = 0; $html < count($items); $html++) {
$$items[$html] = ereg_replace( "\\|", "", $$items[$html]);
$$items[$html]=ereg_replace( "&", "&", $$items[$html]);
$$items[$html]=ereg_replace( "\"", """, $$items[$html]);
$$items[$html]=ereg_replace( "<", "<", $$items[$html]);
$$items[$html]=ereg_replace( ">", ">", $$items[$html]);
}
if (!$fp)
{
echo "<p><strong>Kunne ikke åbne filen '".$filnavn. "'</strong></p>";
}
if ($fp) {
$dump = htmlentities($navn. "|".$mail. "|".time(). "|".$indhold. "|".$url."|".$overskrift."\n");
$gem = fputs($fp, $dump);
fclose($fp);
if ($gem)
{
echo "<p><font face=\"tahoma\"><small><center>Det du skrev er gemt nu</center></small></font></p>";
}
if (!$gem)
{
echo "<p><font face=\"tahoma\"><small><center>Det du skrev er desværre ikke gemt</center></small></font></p>";
}
}
}
};
if ($action == "read") {
$fp = fopen($filnavn, r);
while($str = fgets($fp, 4000)) {
$split = split( "\|", $str);
echo "<hr>";
echo "<div align=center><center>
<table>";
echo "<tr><td align=\"center\" colspan=\"2\" width=\"353\" bgcolor=\"#000000\"><font color=\"#ffffff\" face=\"arial\"><big>".$split[5]."</big></font></td></tr>\n";
echo "<tr><td class=\"title\" width=\"79\"><font face=\"tahoma\"><small>Navn</small></font></td><td align=\"left\" width=\"270\"><font face=\"tahoma\"><small>".$split[0]. "</small></font></a></td></tr>\n";
echo "<tr><td class=\"title\" width=\"79\"><font face=\"tahoma\"><small>E-mail</small></font></td align=\"left\" width=\"270\"><td><font face=\"tahoma\"><small><a href=\"mailto:".$split[1]. "\">".$split[1]. "</a></small></font></td></tr>\n";
echo "<tr><td class=\"title\" width=\"79\"><font face=\"tahoma\"><small>Hjemmeside</small></font></td align=\"left\" width=\"270\"><td><font face=\"tahoma\"><small><a href=\"
http://".$split[4]."\">".$split[4]. "</a></small></font></td></tr>\n";
echo "<tr><td class=\"title\" width=\"79\"><font face=\"tahoma\"><small>Besked</small></font></td><td align=\"left\" width=\"270\"><font face=\"tahoma\"><small>".$split[3]. "</small></font></td></tr>\n";
echo "<tr><td colspan=\"2\" width=\"353\"><hr size=\"1\" color=\"#000000\"></td></tr>\n";
echo "</table>
</center></div>";
}
};
?>
</body>
</html>