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.