在注册表单中使用PHP

时间:2015-02-06 21:50:00

标签: php mysql

我正在创建一个注册表单,我已经查看了一些教程,这是我目前在PHP文件中的内容。

<?php
try {
    $dbh = new PDO("mysql:host=localhost;dbname=NAMEHERE", "USERNAME", "PASSWORD");
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
        header("location: http://mycoinrewards.com");
    die('Failed to connect to database');
}

function NewUser()
{
        global $dbh;
        $username = trim($_POST['username']); //at a minimus clear whitespace.
        $email = trim($_POST['email']);
        $password =  trim($_POST['password']);
        $options = [
            'cost' => 12, //higher = more lower= less. you want it to take around 0.4 seconds for security reasons!
        ];
        $password = password_hash($password, PASSWORD_BCRYPT, $options); // hashed password for storage!
        $stmt = $dbh->perpare("INSERT INTO login (username, email, password) VALUES (?,?,?,?)");
        $stmt->bindValue(2,$username,PDO::PARAM_STR);
        $stmt->bindValue(3,$email,PDO::PARAM_STR);
        $stmt->bindValue(4,$password,PDO::PARAM_STR);
        if($stmt->execute())
        {
        echo "YOUR REGISTRATION IS COMPLETED...";
        }
}

function SignUp()
{
global $dbh;
if(!empty($_POST['username']))   //checking the 'user' name which is from Sign-Up.html, is it empty or have some text
{
        $user = trim($_POST['username']);
        $pass = trim($_POST['password']);
        $stmt = $dbh->prepare("SELECT * FROM login WHERE username = ?") ;
        $stmt->bindValue(1,$_POST['username'],PDO::PARAM_STR);
        $stmt->execute();
        $selected_row = $stmt->fetch(PDO::FETCH_ASSOC);
        if(!password_verify($password, $selected_row['password'])) // check password agaisnt stored hash
        {
                newuser();
        }
        else
        {
                echo "SORRY...YOU ARE ALREADY REGISTERED USER...";
        }
}
}
if(isset($_POST['submit']))
{
        SignUp();
}
?>

当我使用表单提交它时,我在第43行收到错误:致命错误:在第43行的/home/swarm/public_html/logininfo.php中调用未定义的函数password_verify()

如果有人可以帮我修改我的代码,那我就更难了!谢谢!

0 个答案:

没有答案