-1
誰かがこのコードにrecaptchaを追加してくれますか?recaptchaを実装する必要があります
ここに私のPHPレジスタです。
//if form has been submitted process it
if(isset($_POST['submit'])){
//very basic validation
if($_POST['username'] == ''){
$error[] = 'Username is required.';
}else if(strlen($_POST['username']) < 6){
$error[] = 'Username is too short. (6 Chars)';
}else if(strlen($_POST['username']) > 32){
$error[] = 'Username is too long. (32 Chars)';
}else if(preg_match('/[^a-z0-9_]/', $_POST['username'])){
$error[] = 'Only a-z, 0-1 and _ are allowed in username.';
} else {
$stmt = $db->prepare('SELECT username FROM members WHERE username = :username');
$stmt->execute(array(':username' => $_POST['username']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if(!empty($row['username'])){
$error[] = 'Username provided is already in use.';
}
}
//email validation
if($_POST['email'] == ''){
$error[] = 'Email Address is required.';
}else if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
$error[] = 'Please enter a valid Email Address';
} else {
$stmt = $db->prepare('SELECT email FROM members WHERE email = :email');
$stmt->execute(array(':email' => $_POST['email']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if(!empty($row['email'])){
$error[] = 'Email Address provided is already in use.';
}
}
if($_POST['mobile'] == ''){
$error[] = 'Mobile Number is required.';
}else if(!is_numeric($_POST['mobile'])){
$error[] = 'Mobile Number should be numeric.';
}else if(strlen($_POST['mobile']) < 10){
$error[] = 'Mobile Number is too short.';
}
else if(strlen($_POST['mobile']) > 10){
$error[] = 'Mobile Number is too long.';
} else {
$stmt = $db->prepare('SELECT mobile FROM members WHERE mobile = :mobile');
$stmt->execute(array(':mobile' => $_POST['mobile']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if(!empty($row['mobile'])){
$error[] = 'Mobile Number is already in use.';
}
}
if($_POST['password'] == ''){
$error[] = 'Password is required.';
}else if(strlen($_POST['password']) < 6){
$error[] = 'Password is too short. (6 Chars)';
}else if(strlen($_POST['passwordConfirm']) < 6){
$error[] = 'Confirm password was too short. (6 Chars)';
}else if($_POST['password'] != $_POST['passwordConfirm']){
$error[] = 'Passwords do not match.';
}
//if no errors have been created carry on
if(!isset($error)){
//hash the password
$hashedpassword = $user->password_hash($_POST['password'], PASSWORD_BCRYPT);
//create the activasion code
$activation = md5(uniqid(rand(),true));
$usrname = str_replace(' ', '', $_POST['username']);
$usrname = preg_replace('/\s+/','',$_POST['username']);
try {
//insert into database with a prepared statement
$stmt = $db->prepare('INSERT INTO members (username,password,email,mobile,active) VALUES (:username, :password, :email, :mobile, :active)');
$stmt->execute(array(
':username' => strtolower($usrname),
':password' => $hashedpassword,
':email' => $_POST['email'],
':mobile' => $_POST['mobile'],
':active' => $activation
));
header('Location: register.php?action=joined');
exit;
//else catch the exception and show the error.
} catch(PDOException $e) {
$error[] = $e->getMessage();
}
}
}
recaptchaの統合に関するチュートリアルはオンラインで入手できます。あなたはそれをgoogledしましたか? [tutsplus link](http://smal.me.pn/QLCJ) – Thamilan
私は試しましたが、私は植え付けることができません。私はまだPHPに新しい、私のウェブサイトは他人によって開発された。私は誰かに助けに感謝する、私はこれをスパマーをブロックするために追加する –
@タミランによってリンクされたチュートリアルは、最初のGoogleの結果ですが、実際は全く役に立たず、古いです。少なくとも2つのコメントが便利です。ここでは、[GitHub](https://github.com/google/recaptcha/tree/d3274db7c061770472b8eff8a7dbae0871f6cf03)より詳しい説明があります。私は完全に動作するコードでお答えしたいと思いますが、私もそれに取り組んでいます – Brigo