$connection = DB::connect($dsn, true); if (DB::isError($connection)) { trigger_error($connection->getMessage(), E_USER_ERROR); } // Check if the user is already logged in if (isset($_SESSION["loginUsername"])) { $_SESSION["message"] = "You are already logged in!"; header("Location: " . S_HOME); exit; } // Register and clear an error array - just in case! if (isset($_SESSION["loginErrors"])) { unset($_SESSION["loginErrors"]); } $_SESSION["loginErrors"] = array(); // Set up a formVars array for the POST variables $_SESSION["loginFormVars"] = array(); foreach ($_POST as $varname => $value) { $_SESSION["loginFormVars"]["{$varname}"] = pearclean($_POST, $varname, 50, $connection); } // Validate password -- has it been provided and is the length between 6 and // 8 characters? if (checkMandatory("loginPassword", "password", "loginErrors", "loginFormVars")) { checkMinAndMaxLength("loginPassword", 6, 8, "password", "loginErrors", "loginFormVars"); } // Validate email -- has it been provided and is it valid? if (checkMandatory("loginUsername", "email/username", "loginErrors", "loginFormVars")) { emailCheck("loginUsername", "email/username", "loginErrors", "loginFormVars"); } // Check if this is a valid user and, if so, log them in checkLogin($_SESSION["loginFormVars"]["loginUsername"], $_SESSION["loginFormVars"]["loginPassword"], $connection);
header('Content-Type: text/html; charset=utf-8'); require_once __DIR__ . '/models/userRegistration.php'; DBconnect(); if (!empty($_POST)) { $regitrationdate = time(); $errors = array(); if (!empty($_POST["login"])) { $login = $_POST["login"]; } else { $errors['login'] = '******'; } //Проверка правильности email if (!empty($_POST["email"])) { if (!preg_match("/^[a-z][a-z0-9_\\.\\-]{1,23}@([a-z][a-z0-9\\-]{1,24}\\.){1,3}[a-z]{2,6}\$/i", $email = trim($_POST["email"]))) { $errors['email'] = "Неподходящий Email адрес"; } elseif (emailCheck()) { $errors['email'] = "Такой email уже зарегистрирован"; } else { $email = $_POST["email"]; } } else { $errors['email'] = "поле Email не может быть пустым"; } if (!empty($_POST['pass'])) { $pass = strlen($_POST['pass']); //Проверяем длинну пароля if ($pass < 6) { $errors['pass'] = "******"; } else { $pass = md5($_POST["pass"]); }
<?php require 'controller.php'; $name = $_POST['name']; $phoneNumber = $_POST['phoneno']; $emailId = $_POST['email']; $dob = $_POST['dob']; $gender = $_POST['gender']; $membershipType = $_POST['membership_type']; $hNo = $_POST['hno']; $street = $_POST['street']; $city = $_POST['city']; $place = $_POST['state']; $zip = $_POST['pin']; if (emailCheck($emailId)) { $validate = 1; } else { $validate = requestingMembership($name, $phoneNumber, $emailId, $dob, $gender, $membershipType, $hNo, $street, $city, $place, $zip); $validate = "Successfully applied your form"; } echo $validate;
$newPhone = trim($_POST['myPhone']); $newCperson = trim($_POST['myCperson']); $newCPhone = trim($_POST['myCphone']); $newEmail = trim(filter_input(INPUT_POST, 'myEmail')); $newWebsite = trim($_POST['myWeb']); $newNotes = trim($_POST['myNotes']); $newCUsername = trim($_POST['cUsername']); $newCPassword = trim($_POST['cPassword']); //check for empty first name/company name if (emptyTest($newFname)) { $namescheck = true; } else { $error = $error . "First Name Required!"; } //check email if (emailCheck($newEmail)) { $emailcheck = true; } else { $error = $error . "Invalid Email."; } if (phoneCheck($newPhone, 10)) { $telephonecheck = true; } else { $error = $error . "Invalid Phone."; } if ($emailcheck == true && $namescheck == true && $telephonecheck == true) { //insert into database $sql = "INSERT INTO Aegis_Client (FirstName, LastName, EandO, CompanyPhone, ContactPerson, ContactPhone, Email, WebsiteURL, Notes, CompanyUsername, CompanyPassword) VALUES('" . $newFname . "','" . $newLname . "','" . $newEO . "','" . $newPhone . "','" . $newCperson . "','" . $newCPhone . "','" . $newEmail . "','" . $newWebsite . "','" . $newNotes . "','" . $newCUsername . "','" . $newCPassword . "')"; $result = mysqli_query($con, $sql) or die("Error in the consult.." . mysqli_error($con)); //send the query to the database or quit if cannot connect //add our elements to the the respective arrays
function dataCheck($checkArr = array()) { //验证类型 switch ($checkArr['checkType']) { //非空 case 'notnull': if (empty($checkArr['field'])) { return false; } break; //只能是数字 //只能是数字 case 'number': //数字字符串验证 if (!is_numeric($checkArr['field'])) { return false; } //数字长度验证 if (is_numeric($checkArr['length'])) { if (strlen($checkArr['field']) != $checkArr['length']) { return false; } } else { @(list($minlength, $maxlength) = explode('-', $checkArr['length'])); if (strlen($checkArr['field']) < $minlength or strlen($checkArr['field']) > $maxlength) { return false; } } break; //只能是字符串 //只能是字符串 case 'string': break; //只能是数字+字符串 //只能是数字+字符串 case 'numberstring': break; //非0 //非0 case 'not0': if ($checkArr['field'] == 0) { return false; } break; //记录存在 //记录存在 case 'unique': $table = ucwords($checkArr['table']); $model = model($checkArr['table']); $checkData = array('condition' => array($checkArr['field'] => trim($checkArr['value']))); if ($model->find($checkData)) { return false; } break; //邮箱真实 //邮箱真实 case 'email': if (!emailCheck($checkArr['field'])) { return false; } break; //手机号 //手机号 case 'phone': if (!phoneCheck($checkArr['field'])) { return false; } break; //字符长度 //字符长度 case 'length': if (strlen($checkArr['field']) < $checkArr['minlength'] or strlen($checkArr['field']) > $checkArr['maxlength']) { return false; } break; //字段相等 //字段相等 case 'equal': if ($checkArr['field'] != $checkArr['field2']) { return false; } break; //等于指定值 //等于指定值 case 'eqvalue': if ($checkArr['field'] == $checkArr['value']) { return false; } break; //条件验证记录存在 //条件验证记录存在 case 'exists': $model = model($checkArr['table']); if ($model->find($checkArr['condition'])) { return false; } break; default: return false; break; } return true; }
checkMandatory("city", "city", "custErrors", "custFormVars"); // Validate Zipcode if (checkMandatory("zipcode", "Zip code", "custErrors", "custFormVars")) { checkZipcode("zipcode", "Zip code", "custErrors", "custFormVars"); } // Phone is optional, but if it is entered it must have correct format if (!empty($_SESSION["custFormVars"]["phone"])) { checkPhone("phone", "telephone", "custErrors", "custFormVars"); } // Validate Date of Birth if (checkMandatory("birth_date", "date of birth", "custErrors", "custFormVars")) { checkDateAndAdult("birth_date", "date of birth", "custErrors", "custFormVars"); } // Only validate email if this is an INSERT if (!isset($_SESSION["loginUsername"])) { if (checkMandatory("loginUsername", "email/username", "custErrors", "custFormVars") && emailCheck("loginUsername", "email/username", "custErrors", "custFormVars")) { // Check if the email address is already in use in // the winestore $query = "SELECT * FROM users WHERE user_name = \n '{$_SESSION["custFormVars"]["loginUsername"]}'"; $result = $connection->query($query); if (DB::isError($result)) { trigger_error($result->getMessage(), E_USER_ERROR); } if ($result->numRows() == 1) { $_SESSION["custErrors"]["loginUsername"] = "******" . "email address."; } } // Validate password - between 6 and 8 characters if (checkMandatory("loginPassword", "password", "custErrors", "custFormVars")) { checkMinAndMaxLength("loginPassword", 6, 8, "password", "custErrors", "custFormVars"); }
function handreg($nickname, $email, $password) { require_once "../global.php"; error_reporting(~E_ALL); $email = strtolower(stripslashes(trim($email))); $nickname = filterCode($nickname, true); $password = stripslashes($password); if (!emailCheck($email)) { $remsg["msg"] = "邮件地址不正确1" . $email; $remsg["jg"] = "2"; return $remsg; } $nicknameError = checkNickname($nickname); if ($nicknameError != "") { $remsg["msg"] = $nicknameError; $remsg["jg"] = "2"; return $remsg; } if (substr_count($password, " ") > 0) { $remsg["msg"] = "密码不能使用空格2"; $remsg["jg"] = "2"; return $remsg; } if (strlen($password) < 6 || strlen($password) > 26) { $remsg["msg"] = "密码长度不合法3"; $remsg["jg"] = "2"; return $remsg; } $DB = database(); if (PHPSay::getMemberCount($DB, "email", $email) != 0) { $remsg["msg"] = "邮件地址已被占用,请进行帐号绑定4"; $remsg["jg"] = "3"; return $remsg; } else { if (PHPSay::getMemberCount($DB, "nickname", $nickname) != 0) { $remsg["msg"] = "昵称已被占用,请进行帐号绑定5"; $remsg["jg"] = "3"; return $remsg; } else { $userID = PHPSay::memberJoin($DB, $nickname, $email, md5($password), ""); if ($userID > 0) { newAvatar($userID, ""); loginCookie($PHPSayConfig['ppsecure'], $userID, $nickname, 1); $remsg["msg"] = "注册成功"; $remsg["jg"] = "1"; return $remsg; } else { $remsg["msg"] = "注册失败6"; $remsg["jg"] = "2"; return $remsg; } } } $DB->close(); }