Me Pez Me Pez



Home| Links Info| Partners| About Us| Listings
Register | Login  | Tutorials| Policies| Contact Us

 !  Form with PHP - thus far - Tutorial 3 - page 4

<?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 {

if (is_array($_POST)) {
while (list($key, $value) = each($_POST)) {
if ($key != submit || $key != comments) {
echo '<p>The number of characters in ' . $key . ' is ' . strlen($value) . '.<br />';

echo htmlspecialchars("$key: $value") . '<br />';
}
if (eregi("MIME-Version:",$value) || eregi("multipart/",$value) || eregi("\n",$value) || eregi("{",$value) || eregi("\r",$value) || eregi("}",$email) || eregi("<",$value) || eregi(">",$value) || eregi("\|",$value) || eregi("%0a",$value) || eregi("%0d",$value) || eregi("bcc:",$value) || eregi("cc:",$value) || eregi("to:",$value) || eregi("content-type:",$value) )
{
die("<p>Please double check your $key. To prevent someone from spamming from the $key 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 (&gt;), the less than symbol (&lt;), info enclosed within these symbols ... Invalid additional input = $value. Missing characters may include &lt;?php, &lt;body&gt;, &lt;/html&gt;,etc.</p>");
}
if (eregi("\|",$value) || eregi("\[",$value) || eregi("\]",$value) || eregi("\~",$value) || eregi("\`",$value) || eregi("\^",$value) || eregi("\*",$value) || eregi("&",$value) || eregi("\+",$value) || eregi("=",$value) || eregi("#",$value) )
{
$keyone = "1";
die('<p>Please find another way of entering your ' . $key . '. Certain standard keyboard characters are not needed to fill out the ' . $key . ' section of this form.
These unnecessary characters trigger this form to shut down to prevent their use in viruses, spam injections or other malware.
You are reading this message because you have used one, or more, of these characters. The list of
unnecessary characters are as follows: the pipe symbol (|), rectangular parenthesis ([]), the asterisk (*), the ampersand (&), the plus sign (+), the equal sign (=), the number or pound sign (#) and various other characters like ~, `, ^.
If you wish to complete this form, please hit the "back" button on your browser.
This will return you to your form.
Then, if possible, edit your ' . $key . ' so that it is composed of alphabetic characters and non-alphabetic characters other than those listed above. Thankyou. And ' . $key . 'one = ' . ($keyone) . '.</p>');
}
}
}

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;
}

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;
}

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 from 0 to ' . ($firstone) . '.</p>';
exit;
}
if ((eregi ("[a-zA-Z]{1,}['|-]{1,}$",stripslashes(trim($first)))) | (eregi ("[a-zA-Z]{1,}[.]{2,}$",stripslashes(trim($first)))) | (eregi ("[.|'|-]{2,}[a-zA-Z]{1,}",stripslashes(trim($first)))) | (eregi ("^[.|'|-]{1,}[a-zA-Z]{1,}",stripslashes(trim($first))))) {
$firstone = "6";
echo '<p>But your first name, ' . ($first) . ', includes unnecessary non-alphabetic characters.
These non-alphabetic characters may have been placed inappropriately - say, at the beginning
of the name you entered or, in the case of the hyphen or single quote, at the end of the
name you entered. Or, perhaps you accidently held a key down longer than intended.
Whatever the reason, your first name has an inappropriately placed non-alphabetic character or
includes a repetition of non-alphabetic characters - either periods, single quotes, or hyphens.
This repetition of non-alphabetic characters or inappropriate placement of non-alphabetic
characters needs to be corrected before this form can be processed.
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 first name blank or enter a first name composed of alphabetic characters
and non-alphabetic characters in a manner appropriate to their use in common names. Thankyou.
This changes firstone from 0 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 (which was 0) to ' . ($lastone) . '.</p>';
exit;
}
if ((eregi ("[a-zA-Z]{1,}['|-]{1,}$",stripslashes(trim($last)))) | (eregi ("[a-zA-Z]{1,}[.]{2,}$",stripslashes(trim($last)))) | (eregi ("[.|'|-]{2,}[a-zA-Z]{1,}",stripslashes(trim($last)))) | (eregi ("^[.|'|-]{1,}[a-zA-Z]{1,}",stripslashes(trim($last))))) {

$lastone = "6";
echo '<p>But your last name, ' . ($last) . ', includes unnecessary non-alphabetic characters.
These non-alphabetic characters may have been placed inappropriately - say, at the beginning
of the name you entered or, in the case of the hyphen or single quote, at the end of the
name you entered. Or, perhaps you accidently held a key down longer than intended.
Whatever the reason, your last name has an inappropriately placed non-alphabetic character or
includes a repetition of non-alphabetic characters - either periods, single quotes, or hyphens.
This repetition of non-alphabetic characters or inappropriate placement of non-alphabetic
characters needs to be corrected before this form can be processed.
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 non-alphabetic characters in a manner appropriate to their use in common names. Thankyou.
This changes lastone from 0 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.
Expected 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 (\;).
Expected 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 expected 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;
}
}
}


$wordarray = explode(' ', $comment);
echo count($wordarray);
echo '<pre>';
print_r($wordarray);

echo '</pre>';


$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="comment9u.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>

</body></html>


Click here to return to page 7 of the third tutorial.


Your IP address is: 38.103.63.62
 !   Sponsors

We'd like to thank our sponsors for their encouragement and support. If you can use their services, please support us by supporting them.


 !   Dev Shed
Dev Shed - The Open Source Web Development Site Dev Shed
Powered By Dev Shed

More >>
 !   Dev Shed Forum
Dev Shed - The Open Source Web Development Site Dev Shed
Powered By Dev Shed

More >>
 !   Tutorials





Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
More >>

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
More >>

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
More >>

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
More >>

adsense_anim
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
More >>

©2005 ME PEZ BLOGSNOVELSESCAPESHOMEFAQsPOLICIES
REGISTERLOGINFORGOT YOUR PASSWORD?