Kirjautuminen

Haku

Tehtävät

Keskustelu: Koodit: PHP: Vieraskirja

makeuu [03.11.2003 18:15:52]

#

Niinku tällanen kevyt admin- osioton vieraskirja.... admin osio on tulossa piakkoin!

index.php > ei mitn erikoisia
write.php > chomd 777
read.php > chomd 777
config.php> ei mitn

index.php

<!-- laita sinne mihin haluat kirjoitus formin ja viestejen näkyvän! -->
  <CENTER><div class="center">
  <p class="eka"><B>Vieraskirja</B></p>
    <p class="toka">
    <a href="#kirjoita"> - Kirjoita vieraskirjaan - </a><br><br>


    <?php include('read.php'); ?><br><br><br>

    <a name="kirjoita"> Kirjoita vieraskirjaan </a><br>
    <form action="write.php" method="post">
    <table border="0" cellpadding="3" cellspacing="0" width="300">
    <tr>
      <td width="100" height="20" align="left"><b><FONT class="leipa">Nimi: *</FONT></b></td>
      <td width="200" height="20" align="right"><input type="text" maxlength="30" name="name" size="30"></td>
    </tr>
    <tr>
      <td width="100" height="20" align="left"><b><FONT class="leipa">E-mail:</FONT></b></td>
      <td width="200" height="20" align="right"><input type="text" maxlength="60" name="mail" size="30"></td>
    </tr>
    <tr>
      <td width="100" height="20" align="left"><b><FONT class="leipa">WWW:</FONT></b></td>
      <td width="200" height="20" align="right"><FONT class="leipa"><input value="http://" type="text" maxlength="60" name="www" size="30"></td>
    </tr>
    <tr>
      <td width="100" height="20" align="left"><b><FONT class="leipa">Viesti: *</FONT></b></td>
      <td width="200" height="20" align="right">&nbsp;</td>
    </tr>
    <tr>
      <td width="300" height="100" colspan="2" align="center"><textarea rows="8" cols="34" name="data"></textarea></td>
    </tr>
    <tr>
      <td colspan="2" width="200" height="20" align="center"><input type="submit" value=" Lähetä "></td>
    </tr>
    </table>
    </form>
    </p>
  </div>
</CENTER>

write.php

<?php
include('config.php');
$zero = "0";
$name = $_POST['name'];
$mail = $_POST['mail'];
$www = $_POST['www'];
$data = $_POST['data'];
if (!$name) {$zero = "1";}
if (!$data) {$zero = "1";}
if ($zero == "0")
{
$data = wordwrap( $data, $wordwrap, " ", 1 );
	$name = htmlspecialchars($name);
	$name = trim($name);
	$name = str_replace("\n", " ", $name);
	$name = stripslashes($name);
	$mail = htmlspecialchars($mail);
	$mail = trim($mail);
	$mail = str_replace("\n", " ", $mail);
	$mail = stripslashes($mail);
	$www = htmlspecialchars($www);
	$www = trim($www);
	$www = str_replace("\n", " ", $www);
	$www = stripslashes($www);
	$data = htmlspecialchars($data);
	$data = trim($data);
	$data = str_replace("\n", " ", $data);
	$data = stripslashes($data);	$i = 0;
	$rand_key = "1";
	while ($i<11)
	{
		$rand = rand(0, 9);
		$rand_key = $rand_key . $rand;
		$i++;
	}
	$ip = $_SERVER['REMOTE_ADDR'];
	$time = date('d.m.Y H:i');
	$con = $rand_key . $sprtr . $time . $sprtr . $ip . $sprtr . $name . $sprtr . $mail . $sprtr . $www . $sprtr . $data;
	$fp = fopen($db, "a");
	fputs ($fp, "$con\n");
	fclose ($fp);
	header("Location: index.php");
	exit;
}
else
{
	exit("Et täyttänyt kaikkia tarvittavia kohtia, nimi ja viesti ovat pakollisia!");
}
?>

read.php

<?php
include('config.php');

$fields = file("$db");
$fields = array_reverse($fields);
$maxlines = count($fields);
$pages = ceil($maxlines / $maxperpage);
print "<div>\n";
print "<table width=\"480\" border=\"0\" cellspacing=\"1\" bgcolor=\"#BBBBBB\">\n";
print "<tr><td bgcolor=\"#D5EAFF\" valign=\"middle\">\n";
for ($i=1; $i <= $pages; $i++)
{
print ("<FONT class='leipa'><a href=\"page=" . $i . "\">" . $i . "</a> \n");
}
print "<FONT class='leipa'><a href=\"page=0.2\">Kaikki </a>\n";
print "</td></tr>\n";
print "</table><br>\n";

$page = $_GET['page'];

if ($page == 0.2)
{
$i = 0; $max = $maxlines;
}
else
{
 if ($page == 1)
 {
 $i = 0; $max = $maxperpage - 1;
 }
 else
 {
 $i = $page * $maxperpage - $maxperpage; $max = $page * $maxperpage - 1;
 }
}
if (empty($page))
{
$i = 0; $max = $maxperpage - 1;
}

while ($i <= $max)
{
  if (empty($fields[$i]))
  {
  print " ";
  $i++;
  }
  else
  {
    list($rand_key, $time, $ip, $name, $mail, $www, $data) = explode("$sprtr", $fields[$i]);
    $i++;
    print "<table width=\"480\" border=\"0\" cellspacing=\"1\" cellpadding=\"3\" bgcolor=\"#BBBBBB\">\n";
    print "<tr><td bgcolor=\"#D5EAFF\"><FONT class='leipa'>\n";
    print "$time\n";
    print " - $name\n";

    if (!empty($mail))
    {
    print " - ( <a href=\"mailto:$mail\">email</a> |\n";
    } else {
    print " - ( email |\n";
    }

    if (!empty($www))
    {
    print " <a href=\"http://$www\">www</a> )\n";
    } else {
    print " www )\n";
    }

    print "</td></tr><tr><td bgcolor=\"#EAF4FF\"><FONT class='leipa'>\n";
    print $data;
    print "</td></tr>\n";
    print "</table><br>\n";
  }
}
print "<table width=\"480\" border=\"0\" cellspacing=\"1\" bgcolor=\"#BBBBBB\">\n";
print "<tr><td valign=\"middle\"bgcolor=\"#D5EAFF\">\n";
for ($i=1; $i <= $pages; $i++)
{
print ("<FONT class='leipa'><a href=\"page=" . $i . "\">" . $i . "</a> \n");
}
print "<FONT class='leipa'><a href=\"page=0.2\">Kaikki </a>\n";
print "</td></tr>\n";
print "</table>\n";

print "</div>\n";
?>

config.php

<?php
$wordwrap = "20";						// Wordwrap.
$maxperpage = "10";						// maksimi viestimäärä sivulla
$sprtr = "\t";							// separator.
$db = "data/db.txt";						// viestien tekstitiedosto
?>

Vastaus

Aihe on jo aika vanha, joten et voi enää vastata siihen.

Tietoa sivustosta