Kód: Vybrať všetko
<?php
// protects against sending the same message by using refresh button
// (header('location') will "unset" the variables)
if ( array_key_exists('sent', $_POST) )
{
header('./location: ' . $_SERVER['HTTP_REFERER']);
}
$file = 'messages.html';
// write message into the text file
function send_msg($text, $name, $time, $subject='', $email='')
{
global $file;
$who = 'Message sent by ';
$when = ' on ';
$address = 'E-mail: ';
$title = 'Subject: ';
$subject = ( $subject != '' ) ? $subject : '<i>none</i>';
$email = ( $email != '' ) ? $email : '<i>none</i>';
//edits user input
$text = str_replace("<", "&", $text);
$text = str_replace(">", "&", $text);
$text = str_replace("\n", "\n<br />\n", $text);
if(file_exists($file))
{
// opens file in the update mode
$fp = fopen($file, 'a');
// change acording to your needs (font size, colors etc..)
fputs($fp, $who . '<b>' . $name . '</b>' . $when . $time . '<br />');
fputs($fp, $address . '<b>' . $email . '</b>' . '<br />');
fputs($fp, $title . '<b>' .$subject . '</b><br /><br />');
fputs($fp, $text . '<br /><hr />');
fclose($fp);
}
else
{
echo 'Couldn\'t load the guestbook';
}
}
if (!empty($_POST))
{
send_msg($_POST['message'], $_POST['nick'], date('d.m.y'), $_POST['subject'], $_POST['email']);
}
?>
<form method="post">
Nickname: <input type="text" name="nick"><br />
E-mail: <input type="text" name="email"><br />
Subject: <input type="text" name="subject"><br /><br />
<textarea name="message" rows="10" cols="70">
</textarea><br /><br />
<input type="submit" name="sent">
</form>
<?php
// opens file in the readonly mode
$fp = fopen($file, 'r');
fpassthru($fp);
fclose($fp);
?>