使用PHP7 PDO重置密码页面?

时间:2019-03-24 16:28:55

标签: php-7

PHP 7的新手,完成了登录和注册页面。我还必须填写一封电子邮件和密码表格,其中显示正确的参数,然后是新密码并重新输入新密码,然后更改提交密码。

我有一个带有参数的“ Korisnik”类:public $ id;公开的$ email;公共密码公共收费公用$ telefon;公开的$ slika; 和功能:

public static function promeni_staru_lozinku($new_password, $id) {
        $db = Database::getInstance();
        $db->update('Korisnik', 'UPDATE korisnici SET password = :password WHERE korisnici.id = :id;',

            [
                ':password' => $new_password,
                ':id' => $id
            ]
        );
        return $id;
    }

但是我不确定是否正确,因为我在数据库中有密码,而不是new_password。

这是我的表格:

<!DOCTYPE html>
<html>
<head>
    <title>Promena lozinke</title>
    <meta charset="utf-8">

    <link rel="stylesheet" href="css/style.css">

    <script>
        function validate(){

            var a = document.getElementById("new_password").value;
            var b = document.getElementById("confirm_new_password").value;
            if (a!=b) {
               alert("Nove lozinke se ne podudaraju");
               return false;
            }
        }
    </script>

</head>

<body>

<h3 id="logo">Promena lozinke</h3>

    <form onSubmit="return validate()" action="logika/promenilozinku.php" method="post">

        <input type="email" name="email" placeholder="Unesite e-mail"><br>
        <input type="password" name="password" placeholder="Unesite staru lozinku"><br>
        <input type="password" name="new_password" id="new_password" placeholder="Unesite novu lozinku"><br>
        <input type="password" name="confirm_new_password" id="confirm_new_password" placeholder="Ponovite lozinku"><br>
        <input type="submit" value="Izmeni">

    </form>


    <a class="login" href="http://localhost/domaci_peti/index.php">Prijava</a><br>
    <a class="register" href="http://localhost/domaci_peti/registracija.php">Registracija</a><br>


</body>
</html>

我尝试完成此操作,但仍然无法正常工作

<?php

if (!isset($_POST['email'])) {
    header('Location: ../index.php');
    die();
}

require_once __DIR__ . '/../tabele/Korisnik.php';

$korisnik = Korisnik::login($_POST['email'],
                            $_POST['password']);

if ($korisnik !== null) {
    session_start();
    $_SESSION['korisnik_id'] = $korisnik->id;
    $id = Korisnik::promeni_staru_lozinku( $_POST['new_password']
                                );

if ($id > 0) {
    header('Location: ../index.php');
    die();
} else {
    header('Location: ../lozinka.php?error=1');
    die();
}
} else {
    echo "<script type='text/javascript'>alert(\"Pogrešni podaci za prijavu\")</script>";
    header("Refresh: 1; url= ../index.php");
    die();
}

0 个答案:

没有答案