示例#1
0
function create_error_string($login, $password, $email, $gender)
{
    $login_pattern = "^\\s+\$";
    $password_pattern = "^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{4,15}\$";
    //^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,8}$
    // Based on a regex by Michael Rushton
    //$email_pattern = '/^(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){255,})(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){65,}@)(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22))(?:\\.(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-+[a-z0-9]+)*\\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-+[a-z0-9]+)*)|(?:\\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\\]))$/iD';
    $errors_occurred = false;
    $error_string = "Errors: <ul>";
    if (strlen(trim($login)) == 0 || preg_match($login_pattern, $login)) {
        $error_string .= "<li>login cannot be empty nor contain spaces</li>";
        $errors_occurred = true;
    }
    // preg_match form of validation
    if (!$password == null && !preg_match($password_pattern, trim($password))) {
        $error_string .= "<li>password must be at least 4 characters, no more than 15 characters, and must include at " . "least one upper case letter, one lower case letter, and one numeric digit</li>";
        $errors_occurred = true;
    }
    // other form of validation
    if (!filter_var(trim($email), FILTER_VALIDATE_EMAIL)) {
        $error_string .= "<li>invalid email</li>";
        $errors_occurred = true;
    }
    // medieval way of  validation
    if (strlen(trim($gender)) != 1 && !(strcmp($gender, "M") || strcmp($gender, "F"))) {
        $error_string .= "<li>gender must be chosen</li>";
        $errors_occurred = true;
    }
    $error_string .= "</ul>";
    if ($errors_occurred) {
        $_SESSION['warning'] = message_warning($error_string);
        return $error_string;
    } else {
        return "";
    }
}
    echo "<li><a href=\"../../php/logout.php\">logout</a></li>";
}
?>
                        </ul>
                    </li>
                </ul>
            </nav>
        </header>

        <section class="content">
            <h2>data manipulation</h2>
            <article class="card_slightly_extended_width">
                <h3>user edit</h3>
                <?php 
if (!isset($_SESSION['user_to_edit'])) {
    print message_warning("No user is set to be edited.");
} else {
    $user_row = $_SESSION['user_to_edit'];
    $login = $user_row[0];
    $password = "";
    $email = $user_row[4];
    $note = $user_row[6];
    $superuser = false;
    if ($user_row[3] == "t") {
        $superuser = true;
    }
    $superuser_checked = "";
    if ($superuser) {
        $superuser_checked = "checked";
    }
    $gender_string = $user_row[5];