Why not satisfy the condition or enter if output the user name format exception qaq

Source: Internet
Author: User
Why not satisfy the condition or enter if output username format error Qaq
Enter format to check the values of each variable


But strlen ($username) =9
Result1=1
Or will you run into if?
Output User name format error


This is the only paragraph in the entire code. "Bad User name format"
[/IMG]


$posts =$_post;
foreach ($posts as $key = = $value) {
if (empty ($value))
Exit (' Illegal access! ');
}
foreach ($posts as $key = = $value) {
$posts [$key] = Trim ($value);
}
Require (' dbconfig.php ');
Registered
function register ($username, $password, $email) {
$query = "Insert UserData values ('". $username. "', '". $password. "', '". $email. "')";
$result =mysql_query ($query);
if (! $result) {
Exit (' Registration failed!PAPAP ');
Die (' Registration failed '. Mysql_error ());
}
else{
echo "registered successfully!";
}
}
Check user name, password, mailbox format
function Verifyformat ($username, $password, $email) {
$result 1=preg_match ("/^[\x{4e00}-\x{9fa5}]+$/u", $username);
if (strlen ($username) <1 | | strlen ($username) >16 | | result1==0) {
echo "User name format is wrong!";
return false;
Die ("User name format is wrong!");
}

$result 2=preg_match ("/^\w+$/u", $password);
if (strlen ($password) <6 | | strlen ($password) >17 | | result2==0) {
echo "Bad password format!";
return false;
Die ("Bad password format!");
}

$result 3=preg_match ("/^[a-za-z\d]+@[a-za-z\d]+\.[ Com|cn|com.cn|net]+$/u ", $email);
if (result3==0) {
echo "Bad mailbox format!";
return false;
Die ("Bad mailbox format!");
}
return true;
}
$flag =verifyformat ($posts [' username '], $posts [' Password '], $posts [' email '];
if ($flag)
Register ($posts [' username '], $posts [' Password '], $posts [' email '];
Else
Die ("Registration failed!!..");
?>



------Solution--------------------
The owner said the right.
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.