<?php
require 'config.php';
$success=FALSE;
if(!empty($_POST))
{
$username = $_POST['username'];
$username = strip_tags($username);
$password = $_POST['password'];
$password = strip_tags($password);
$password = md5($password);
$email = $_POST['email'];
$email = strip_tags($email);
$name = $_POST['name'];
$name = strip_tags($name);
$sql="SELECT * FROM users WHERE username='$username'";//username check
$esql="SELECT * FROM users WHERE email='$email'"; //email check
$eqry=mysql_query($esql); // email made query
$qry=mysql_query($sql); //username made query
$num_rows = mysql_num_rows($qry);
$enum_rows= mysql_num_rows($eqry);
if($num_rows>0 )
{
echo 'Username already taken';
}
else if ($enum_rows>0)
{
echo 'email already registered';
}
else
{
$success=mysql_query("INSERT INTO users (username,password,email,name) VALUES ('$username','$password','$email','$name')");
}
if($success)
{
header('Location:regthank.html');
}
}
?>
答案 0 :(得分:1)
之后
$email = $_POST['email'];
$email = strip_tags($email);
你可以像这样检查
$is_valid_email = filter_var($email, FILTER_VALIDATE_EMAIL);
这将返回true
或false
。
然后如果$is_valid_email
为false
,请确保此部分无法执行:
} else {
$success=mysql_query("INSERT INTO users (username,password,email,name) VALUES ('$username','$password','$email','$name')");
}
答案 1 :(得分:0)
$message = "Your Activation Code is ".$code."";
$to=$email;
$subject="Activation Code For Talkerscode.com";
$from = 'your email';
$body='Your Activation Code is '.$code.' Please Click On This link <a href="verification.php">Verify.php?id='.$db_id.'&code='.$code.'</a>to activate your account.';
$headers = "From:".$from;
mail($to,$subject,$body,$headers);
echo "An Activation Code Is Sent To You Check You Emails";
插入此代码以向用户发送电子邮件,以确认完整教程http://talkerscode.com/webtricks/account-verification-system-through-email-using-php.php
的电子邮件地址