Name:
Comments:
when someone send the form, i often see information like this submitted: (example)
Name: zzzzzzzzzzzzz
comments: PHP is so cool. i love PHP
well this was very annoying, as you can see the name is abviously not correct. one way to check for a valid's user's name is with PHP.
I wrote this script so you can see how it works. this snippet shows you how you can block bogus information submitted by users in your forms, like repeated characters or letter or numbers
<img src="http://webune.com/images/headers/default_logo.jpg">
<h1>Checking for repeated letters by webune.com</h1><hr>
<?
if(isset($_REQUEST['Submit']))
{
# FORM HAS BEEN SUMBITTED
$str = $_POST['name'];
$num_char = strlen($str);
echo "You entered: ".$str."<br>";
echo "Number of Characters found: ".$num_char."<br>";
$num_char = $num_char - 1;
for($counter =0; $counter <= $num_char; $counter++)
{
if($str[$counter] == $first || $str[$counter] == $second)
{ $error = 1; break;}
$first = $str[$counter -2 ];
$second =$str[$counter -1 ];
}
if($error)
{
echo '<h2 style="color:red">ERROR: REPEATED LETTERS WERE FOUND</h2>';
}
else
{
echo '<h2 style="color:green">NO ERRORS FOUND</h2>';
}
<h1>Checking for repeated letters by webune.com</h1><hr>
<?
if(isset($_REQUEST['Submit']))
{
# FORM HAS BEEN SUMBITTED
$str = $_POST['name'];
$num_char = strlen($str);
echo "You entered: ".$str."<br>";
echo "Number of Characters found: ".$num_char."<br>";
$num_char = $num_char - 1;
for($counter =0; $counter <= $num_char; $counter++)
{
if($str[$counter] == $first || $str[$counter] == $second)
{ $error = 1; break;}
$first = $str[$counter -2 ];
$second =$str[$counter -1 ];
}
if($error)
{
echo '<h2 style="color:red">ERROR: REPEATED LETTERS WERE FOUND</h2>';
}
else
{
echo '<h2 style="color:green">NO ERRORS FOUND</h2>';
}
echo '<strong><a href="http://www.webune.com">Continue >></a></strong>';
}
else
{
# FORM HAS NOT BEEN SUBMITTED
?>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
Name: <input type="text" name="name">
<input type="submit" name="Submit" value="Submit">
</form>
<?
}
?>
<hr>
<div align="center">PHP Webhosting at <a href="http://www.webune.com">www.webune.com</a></div>
to see the script in action, all you have to do is copy and paste it to your text editor like notepad is you are using windows. once you have paste the code into notepad, save the file as wallpaperama.php then upload to your website. make sure your website has PHP. when you see the script you will see a form asking for information if you enter a name like zzzzzzzz for example the form will error out. this form is good for checking repeating charracters in a string
if your wesbite doesn't have PHP, you can visit www.webune.com and sign up for PHP web hosting. their plans are cheap(affordable) web hosting.
tags: php repeated php repeat php repeat region php repeat string php repeat until php repeat character nested repeat region php php nested repeat php tutorial php functions php redirect php tutorials php arrays php array php explode php isset php include php foreach php scripts php date php fopen php _post php _get php str_replace php forms php variables php echo php sessions smarty php repeated variables php _server php classes php mysql php function php header pear php php _session php mail