<?php
if (isset($_POST['submit'])) { // if the form was submitted.
echo ('<p>Form was submitted.</p>');
$date = date('F j, Y G:i:s');
$first = stripslashes ($_POST['firstname']);
$last = stripslashes ($_POST['lastname']);
$email = stripslashes ($_POST['email']);
$comment = stripslashes ($_POST['comments']);
$refer = getenv("HTTP_REFERER") ;
$firstone = 0 ;
if (empty($first) && empty($last) && empty($email)
&& empty($comment)) {
echo ('<p>The form is blank. As is, the form will be ignored.</p>');
} else {
if (empty($comment)) {
echo ("<p>You haven't entered a comment. Without a comment,
this form cannot be processed. To enter a comment, hit the 'back'
button on your browser, fill in your comment and resubmit. Thankyou.</p>");
exit;
} else {
echo '<p>The number of characters in your first name is ' .
strlen($first) . '.';
if (strlen($first) < 26) {
echo ' This is well within the allowable limit for this input.</p>';
} else {
echo ' This is over the allowable limit of 25 characters.
If your first name is more than 25 characters long, please leave the
first name input box blank and put a sentence in the comment box stating
what your first name is.
To return to the form you just filled out, hit the "back"
button on your browser. Make the necessary changes and resubmit. Thankyou.</p>';
exit;
}
echo '<p>The number of characters in your last name is ' .
strlen($last) . '.';
if (strlen($last) < 26) {
echo ' This is well within the allowable limit for this input.</p>';
} else {
echo ' This is over the allowable limit of 25 characters.
If your last name is more than 25 characters long, please leave the
last name input box blank and put a sentence in the comment box stating
what your last name is.
To return to the form you just filled out, hit the "back"
button on your browser. Make the necessary changes and resubmit. Thankyou.</p>';
exit;
}
echo '<p>The number of characters in your email is ' . strlen($email)
. '.';
if (strlen($email) < 50) {
echo ' This is well within the allowable limit for this input.</p>';
} else {
echo ' This is over the allowable limit of 50 characters.
If your email is more than 50 characters long, please leave the email
input box blank and put a sentence in the comment box stating what
your email is.
To return to the form you just filled out, hit the "back"
button on your browser. Make the necessary changes and resubmit. Thankyou.</p>';
exit;
}
echo '<p>The number of characters in your comment is ' . strlen($comment)
. '.';
if (strlen($comment) < 880) {
echo ' This is well within the allowable limit for this input.</p>';
} else {
echo 'Because of memory limitations, this form is designed to handle
880 characters or less.
You will need to shorten your comment by ' . ((strlen($comment)) -
880) . ' characters so that your comment can be processed.
To return to the form you just filled out, hit the "back"
button on your browser. Make the necessary changes and resubmit. Thankyou.</p>';
exit;
}
if (eregi("MIME-Version:",$first) || eregi("multipart/",$first)
|| eregi("\n",$first) || eregi("{",$first) ||
eregi("\r",$first) || eregi("}",$email) || eregi("@",$first)
|| eregi("<",$first) || eregi(";",$first) ||
eregi("\;",$first) || eregi("%0a",$first) || eregi("%0d",$first)
|| eregi("bcc:",$first) || eregi("cc:",$first)
|| eregi("to:",$first) || eregi("content-type:",$first)
)
{
die("<p>To prevent someone from spamming from the firstname
section of this form, certain special characters and phrases trigger
this form to shut down. The special characters and phrases appear
after the following equal sign. If nothing suspicious shows immediately
after the equal sign, the missing characters are in machine language
or are coded characters - characters like the greater than symbol
(>), the less than symbol (<), info enclosed within
these symbols ... Invalid additional input = $first. Missing characters
may include <?php, <body>, </html>,
etc.</p>");
}
if (eregi("MIME-Version:",$last) || eregi("multipart/",$last)
|| eregi("\n",$last) || eregi("{",$last) || eregi("\r",$last)
|| eregi("}",$email) || eregi("@",$last) || eregi("<",$last)
|| eregi(";",$last) || eregi("\;",$last) || eregi("%0a",$last)
|| eregi("%0d",$last) || eregi("bcc:",$last) ||
eregi("cc:",$last) || eregi("to:",$last) || eregi("content-type:",$last)
)
{
die("<p>To prevent someone from spamming from the lastname
section of this form, certain special characters and phrases trigger
this form to shut down. The special characters and phrases appear
after the following equal sign. If nothing suspicious shows immediately
after the equal sign, the missing characters are in machine language
or are coded characters - characters like the greater than symbol
(>), the less than symbol (<), info enclosed within
these symbols ... Invalid additional input = $last. Missing characters
may include <?php, <body>, </html>,
etc.</p>");
}
if (eregi("MIME-Version:",$email) || eregi("multipart/",$email)
|| eregi("\n",$email) || eregi("{",$email) ||
eregi("\r",$email) || eregi("}",$email) || eregi("<",$email)
|| eregi(";",$email) || eregi("\;",$email) ||
eregi("%0a",$email) || eregi("%0d",$email) ||
eregi("bcc:",$email) || eregi("cc:",$email) ||
eregi("to:",$email) || eregi("content-type:",$email)
)
{
die("<p>To prevent someone from spamming from the email
section of this form, certain special characters and phrases trigger
this form to shut down. The special characters and phrases appear
after the following equal sign. If nothing suspicious shows immediately
after the equal sign, the missing characters are in machine language
or are coded characters - characters like the greater than symbol
(>), the less than symbol (<), info enclosed within
these symbols ... Invalid additional input = $email. Missing characters
may include <?php, <body>, </html>,
etc.</p>");
}
if (eregi("MIME-Version:",$comment) || eregi("multipart/",$comment)
|| eregi("\n",$comment) || eregi("{",$comment)
|| eregi("\r",$comment) || eregi("}",$email) ||
eregi("<",$comment) || eregi(">",$comment)
|| eregi("\|",$comment) || eregi("\[",$comment)
|| eregi("\]",$comment) || eregi("\~",$comment)
|| eregi("\`",$comment) || eregi("\^",$comment)
|| eregi("\*",$comment) || eregi("&",$comment)
|| eregi("\+",$comment) || eregi("=",$comment)
|| eregi("#",$comment) || eregi("@",$comment)
|| eregi("%0a",$comment) || eregi("%0d",$comment)
|| eregi("bcc:",$comment) || eregi("cc:",$comment)
|| eregi("to:",$comment) || eregi("content-type:",$comment)
)
{
die("<p>Please find another way of making your comment.
To prevent someone from spamming from the comment section of this
form, certain special characters and phrases trigger this form to
shut down. The special characters and phrases appear after the following
equal sign. If nothing suspicious shows immediately after the equal
sign, the missing characters are in machine language or are coded
characters - characters like the greater than symbol (>), the
less than symbol (<), info enclosed within these symbols ...
Invalid additional input = $comment. Missing characters may include
<?php, <body>, </html>,etc.</p>");
}
if (!empty($first)) {
if (!eregi ("^[[:alpha:].' -]{1,25}$",stripslashes(trim($first))))
{
$firstone = "3";
echo '<p>But, your first name, ' . ($first) . ', is NOT composed
of just alphabetic characters.
This form is designed to accept a first name that is either blank
or composed wholely of alphabetic characters and certain non-alphabetic
characters commonly used in names.
You are reading this message because your first name included non-alphabetic
characters not normally associated with common names.
If you made a mistake in entering your first name and wish to complete
this form, or if you just wish to complete this form, please hit the
"back" button on your browser.
This will return you to your form.
Then either leave the firstname blank or enter a first name composed
of alphabetic characters and characters normally associated with common
names. Thankyou. And firstone = ' . ($firstone) . '.';
exit;
} else {
if (eregi ("^[[:alpha:].' -]{1,25}$",stripslashes(trim($first))))
{
$firstone = "0";
echo '<p>Your first name is ' . ($first) . ' And firstone =
' . ($firstone) . '.</p>';
if (eregi ("^[.|'|-]{1,25}$",stripslashes(trim($first))))
{
$firstone = "2";
echo '<p>But your first name, ' . ($first) . ', does not
include any alphabetic characters. Because of this, your first name
is considered an invalid name which causes this
form to shut down. This, in turn, changes firstone to ' . ($firstone)
. '.</p>';
exit;
}
}
}
}
if (!empty($last)) {
if (!eregi ("^[[:alpha:].' -]{1,25}$",stripslashes(trim($last))))
{
$lastone = "3";
echo '<p>But, your last name, ' . ($last) . ', is NOT composed
of just alphabetic characters.
This form is designed to accept a last name that is either blank or
composed wholely of alphabetic characters and certain non-alphabetic
characters commonly used in names.
You are reading this message because your last name included non-alphabetic
characters not normally associated with common names.
If you made a mistake in entering your last name and wish to complete
this form, or if you just wish to complete this form, please hit the
"back" button on your browser.
This will return you to your form.
Then either leave the last name blank or enter a last name composed
of alphabetic characters and characters normally associated with common
names. Thankyou. And lastone = ' . ($lastone) . '.';
exit;
} else {
if (eregi ("^[[:alpha:].' -]{1,25}$",stripslashes(trim($last))))
{
$lastone = "0";
echo '<p>Your last name is ' . ($last) . ' And lastone = ' .
($lastone) . '.</p>';
if (eregi ("^[.|'|-]{1,25}$",stripslashes(trim($last))))
{
$lastone = "2";
echo '<p>But your last name, ' . ($last) . ', does not
include any alphabetic characters. Because of this, your last name
is considered an invalid name which causes this
form to shut down. This, in turn, changes lastone to ' . ($lastone)
. '.</p>';
exit;
}
}
}
}
if (!empty($email)) {
if (!eregi ("^([[:alnum:]]|_|\.|-)+@([[:alnum:]]|\.|-)+(\.)([a-z]{2,4})$",
stripslashes(trim($email)))) {
$eone = "3";
echo '<p>But, your email, ' . ($email) . ', is NOT a standard
email address pattern.
This form is designed to accept an email that is either blank or composed
of normal alphanumeric and certain non-alphanumeric email characters.
You are reading this message because your email address did not match
the expected set of email characters.
If you made a mistake in entering your email and wish to complete
this form, or if you just wish to complete this form, please hit the
"back" button on your browser.
This will return you to your form.
Then either leave the email address blank or enter a standard email
address. Thankyou. And eone = ' . ($eone) . '.';
exit;
} else {
if (eregi ("^([[:alnum:]]|_|\.|-)+@([[:alnum:]]|\.|-)+(\.)([a-z]{2,4})$",
stripslashes(trim($email)))) {
$eone = "0";
echo '<p>Your email is ' . ($email) . ' And eone = ' . ($eone)
. '.</p>';
}
}
}
if (!empty($comment)) {
if (eregi ("^[a-zA-Z0-9\"\.' -?!%,:_\;\$\(\)\/]{1,}$",stripslashes(trim($comment))))
{
$commentone = "0";
echo '<p>Your comment is ' . ($comment) . ' And commentone =
' . ($commentone) . '.</p>';
if (eregi ("^[0-9\"\.' -?!%,:_\;\$\(\)\/]{1,}$",stripslashes(trim($comment))))
{
$commentone = "2";
echo '<p>But your comment ' . ($comment) . ' , does not
include any alphabetic characters. Because of this, your comment is
considered gibberish which causes this
form to shut down. So now commentone = ' . ($commentone) . '.</p>';
exit;
}
} else {
if (!eregi ("^[a-zA-Z0-9\"\.' -?!%,:_\;\$\(\)\/]{1,}$",stripslashes(trim($comment))))
{
$commentone = "3";
echo '<p>But, your comment , ' . ($comment) . ', is either NOT composed of
alphabetic characters or NOT composed of just alphabetic characters.
This form is designed to accept a comment composed wholely of alphabetic
characters and certain non-alphabetic characters and punctuation marks
commonly used in short comments.
Acceptable punctuation normally used in short comments include the
quotation mark ("), the single quote (\'), the question mark
(?), the exclamation mark (!), the period (.), the comma (\,), the
colon (:) and the semicolon (\;).
Acceptable non-alphabetic characters used in short comments include
the underline, the hyphen (-), the percent sign (%), the dollar sign
($), the slash (/) and regular parenthesis \( \).
You are reading this message because your comment included non-alphabetic
characters not normally associated with short comments and not included
in the acceptable non-alphabetic character list above.
If you wish to complete this form, please hit the "back"
button on your browser.
This will return you to your form.
Then enter a comment composed of alphabetic characters and the characters
normally associated with short comments listed above. Thankyou. And
commentone = ' . ($commentone) . '.';
exit;
}
}
}
$mailto = "you@youremail.com";
$subject = "Guest Comment from YOUR WEB SITE.COM";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/plain; charset=iso-8859-1' . "\r\n";
$headers .= 'From: you <you @yourotheremail.com>' . "\r\n";
$body = "$date From: $refer.\n A guest, $first $last\n whose
return email is: $email\n has made this comment:\n $comment\n";
// mail($mailto,$subject,$body,$headers);
$guest_data = "$date\t$refer\t$first\t$last\n\t$email\n\t$comment\n";
if ($fp = @fopen ("guests.txt", "a")) { // Open
the file for writing.
// fwrite ($fp, $guest_data);
fclose ($fp);
echo ('<p>Program executed O.K.</p>');
// echo ('<p>Info filed away in a tabbed array for future reference.</p>');
}
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Guest Comment</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
</head>
<body>
<table bgcolor="#000000" align="center">
<tr><td colspan="2" align="center"><h2><font
color="#FFFFFF">Guest Comment</font></h2></td></tr>
<form name="guest_comment_form" action="comment7.php"
method="post">
<tr><td align="right"><font color="#FFFFFF">First
Name</td>
<td align="left"><input type="text" name="firstname"
size="25" maxsize="20"> </td></tr><tr>
<td align="right"> <font color="#FFFFFF">Last
Name</td>
<td align="left"><input type="text" name="lastname"
size="25" maxsize="20"></td></tr>
<tr><td align="right"><font color="#FFFFFF">Email
Address</td>
<td align="left"><input type="text" name="email"
size="25" maxsize="60""></td></tr>
<tr><td align="right"><font color="#FFFFFF">Comments
or Questions</td>
<td align="left"><textarea name="comments"
rows="4" cols="40"></textarea></td></tr>
<tr><td align="center" colspan="2"><input
type="submit" name="submit" value="Submit!">
<input type="reset" name="Reset" value="Reset"></td>
</tr>
</table>
</form>
<center><p>Click <a href="tutorials3g.php">here
to return to page 7 of the third tutorial</a>.</p></center>
</body></html>
|