我使用php的FILTER_VALIDATE_EMAIL来检查电子邮件的格式是否正确。 当我还在我的本地机器上运行xampp时它工作正常(php 5.5)。 将其上传到实时服务器后,我一直收到电子邮件无效"消息电子邮件是否正确(已检查过php 5.3,5.5和5.6)。
以下是代码:
<?php
//Variables used for registering
$username = mysql_real_escape_string($_POST['username']);
$email = mysql_real_escape_string($_POST['email']);
$password = mysql_real_escape_string($_POST['password']);
$submit = $_POST['register'];
$joindate = date("y.m.d");
//Get data from database to check if a user exists
$userssql = mysql_query("SELECT * FROM users WHERE username = '$username'");
if(isset($submit)) {
if(mysql_num_rows($userssql) == 0) {
if(filter_var($email, FILTER_VALIDATE_EMAIL)) {
$encryptpass = password_hash($password, PASSWORD_DEFAULT);
$register = mysqli_query("INSERT INTO users(username, email, password, joindate) VALUES('$username', '$email', '$encryptpass', '$joindate')");
header("location: login.php");
}
else {
?>
<script type="text/javascript">
$('#email-error').text("Invalid email");
</script>
<?php
}
}
else {
?>
<script type="text/javascript">
$('#username-error').text("Username already exists");
</script>
<?php
}
}
?>
任何想法可能出错?