怎么处理这个错误?

时间:2013-06-14 08:01:52

标签: php user-registration

我的脚本在本地主机WampServer 1st上运行,它在哪里运行,然后将其导出到我的在线实时域。 经过一些调整,我得到了剧本再次部分工作,但我仍然得到以下错误

Call to undefined function filter_var()

此脚本的目的是当用户想要注册它时将验证电子邮件地址并将用户添加到数据库并向用户的电子邮件地址发送验证链接。

这是脚本:

<?PHP
error_reporting(E_ALL);
ini_set('display_errors', 1);
// connection towards database with a include function
include ('connection.php');

if (isset($_REQUEST['send']))
{
    if(isset($_REQUEST['NAAM']))
    {
        $naam = $_REQUEST['NAAM'];
    }

    function spamcheck($field)
    {
        //filter_var() sanitizes the e-mail
        //address using FILTER_SANITIZE_EMAIL
        $field = filter_var($field, FILTER_SANITIZE_EMAIL);

        //filter_var() validates the e-mail
        //address using FILTER_VALIDATE_EMAIL
        if(filter_var($field, FILTER_VALIDATE_EMAIL))
        {
            return TRUE;
        }else
        {
            return FALSE;
        }
    }

    //if "email" is filled out, proceed
    if (isset($_REQUEST['mail']))
    {

        //check if the email address is invalid
        $mailCheck = spamcheck($_REQUEST['mail']);
        if ($mailCheck == TRUE)
        {
            $email = $_REQUEST['mail'];
        }else
        {
            $mailCheck = FALSE;
            echo "Invalid input email";
        }
    }

    if(isset($_REQUEST['question']))
    {
        $quest = $_REQUEST['question'];
        // checks if the filled in Question is de same as the answer novice or Novice
        if ($quest =="novice" or $quest =="Novice")
        {
            $questCheck = TRUE;
        }else
        {
            $questCheck = FALSE;
            echo "Your answer to the question was incorrect!<br>";
        }
    }

    if(isset($_REQUEST['wachtwoord'] , $_REQUEST['c_wachtwoord']))
    {

        $WW = $_REQUEST['wachtwoord'];
        $c_WW = $_REQUEST['c_wachtwoord'];

        // checks if the filled in password is de same as the confirmation password
        if ($WW == $c_WW)
        {
            $pwCheck = TRUE;
        }else
        {
            $pwCheck = FALSE;
            echo "Your filled in passwords are not the same try again!<BR>";
        }
    }       



    // checks if both password confirmation and question are TRUE continue else retrieve fault
    if ($pwCheck && $questCheck && $mailCheck == TRUE)
    {
        $hash = md5( rand(0,1000) );
        // insert all filled in values into the database
        $opdracht1 = "INSERT INTO users (ID , name , password , mail , staffLevel , hash , active) VALUES ('','$naam','$WW','$email','0','$hash','0')";

        // run query 
        if (mysql_query ($opdracht1))
        {
            header( "refresh:5;url=http://www.debeerislos.nl/inlog_user.php" );
            echo "Your account has succesfully been created! Please check your email to validate your account!<BR>";

                    $to      = $email; //Send email to our user
                    $subject = 'Signup | Verification'; //// Give the email a subject 
                    $message = '

                    Thanks for signing up!
                    Your account has been created!
                    You can login with the following credentials:

                    ------------------------
                    Username: '.$naam.'
                    Password: '.$WW.'
                    ------------------------

                    After you have activated your account you will have the rights so you can fully use it.

                    Please click this link to activate your account:
                    http://www.debeerislos.nl/verify_user.php?email='.$email.'&hash='.$hash.'&name='.$naam.'

                    '; // Our message above including the link

                    $headers = 'From:info@debeerislos.nl' . "\r\n"; // Set from headers
                    mail($to, $subject, $message, $headers); // Send the email

        }else
        {
            echo "Woops something went wrong please contact the Administrator of the website or fill in the form again!<br> <A href='http://www.debeerislos.nl/form_register_user.html'>CLICK HERE!</A> to fill in the forum again";
        }
    }elseif ($pwCheck && $questCheck == FALSE)
    {
        echo "you filled both the password confirmation and the answer to the question incorrect!<br>";
    }       
}else
{
    echo "Either you haven't send anything! or you haven't filled in the form<br>";
}
?>

提前谢谢。

亲切的问候, StaleDevil

1 个答案:

答案 0 :(得分:0)

你在哪里定义了filter_var()函数?它没有在您给定的代码中定义。如果您在同一页面中定义它,那么您如何定义?提供示例。否则,如果你在另一个页面中定义它,那么请包含该页面。