簡體   English   中英

注冊激活將不再起作用(不再)

[英]Registration activation wont work (anymore)

因此,幾個月前,我使用com碼(通過電子郵件發送)來激活我的注冊表格。 這種情況是注冊及其激活始終有效。 但是自最近以來,經過一些更改,它突然不再起作用了。 注冊有效,電子郵件正在通過com代碼鏈接發送給我,並且它還說我現在可以登錄,但是一旦我嘗試使用已創建的帳戶登錄,它就會將我發送到我的登錄錯誤(錯誤密碼或電子郵件)。 當我查看數據庫時,我也看到尚未插入數據(其為空)。 我已經看過並做了很多事情,試圖修復它,但沒有一個起作用。 所以,我的最后一招:堆棧;)代碼發布在下面(順便說一句,因為我不認為這是問題所在,所以省略了表單代碼):

用於連接數據庫的代碼為(隨處包含):

    <?php
$user = "XX";
$host = "XX";
$password = "XX"; //http://www.codinghorror.com/blog/2007/09/youre-probably-storing-passwords-incorrectly.html //
$database = "XX";

$conn = new mysqli($host, $user, $password, $database)or die ("Error message");

// check connection
if ($conn->connect_error) {
  trigger_error('Database connection failed: '  . $conn->connect_error, E_USER_ERROR);
}


?>

輸入注冊按鈕后,這是注冊檢查頁面:

session_start();
include('configdb.php');

if(isset($_SESSION['error']))
{

    header("Location: indexresp.php");
    exit;
}
else{   

        if (isset($_POST["submit"])){

            $register = $_POST['submit'];
            $email2 = strip_tags($_POST['email']);

            mysqli_select_db($conn, $database);
            $emailcheck = mysqli_query($conn, "SELECT email from user WHERE email='$email2'");
            $check = mysqli_num_rows($emailcheck);
                if ($check == 0){

                }   

        else {
            $_SESSION['error']['email'] = "This Email is already used.";
            header("Location: indexresp.php");
            exit;
        }

        }

    // the register (form field) data:  
    $voornaam = $_POST['voornaam']; 
    $achternaam = $_POST['achternaam'];
    $email = $_POST['email'];
    $password = $_POST['wachtwoord']; 
    $com_code = md5(uniqid(rand()));

    $sql2 = "INSERT INTO user (email, password, com_code, voornaam, achternaam) VALUES ('$email', '$password', '$com_code', '$voornaam', '$achternaam')";




        require("class.phpmailer.php");

        $mail = new PHPMailer();
        $mail->CharSet = 'UTF-8';
        $mail->IsSMTP();                                      // set mailer to use SMTP
        $mail->SMTPSecure = "tls";
        $mail->Host = "smtp.gmail.com";  // specify main and backup server
        $mail->SMTPAuth = true;     // turn on SMTP authentication
        $mail->Port       = XXX;
        $mail->Username = "XXXXX";  // SMTP username
        $mail->Password = "XXX"; // SMTP password
        $mail->SetLanguage("nl");
        $mail->From = "XXXXX";
        $mail->FromName = "Oblectare";
        $mail->AddAddress("$email");
        // name is optional
        $mail->AddReplyTo("XXXXX", "Information");

        $mail->WordWrap = 50;                                 // set word wrap to 50 characters
        //$mail->AddAttachment("/var/tmp/file.tar.gz");         // add attachments
        //$mail->AddAttachment("/tmp/image.jpg", "new.jpg");    // optional name
        $mail->IsHTML(true);                                  // set email format to HTML

        $mail->Subject = "Account registratie";
        $mail->Body    = "http://localhost/debasis/hoofdstuk03/confirm.php?passkey=$com_code <br>This adress needs to be copyed in the browser and this is your password:<br><br>" .$password;

        $mail->AltBody = "http://localhost/debasis/hoofdstuk03/confirm.php?passkey=$com_code. This adress needs to be copyed in the browser and this is your password:" .$password;
        if(!$mail->Send())
        {
            echo "Error mail<p>";
            echo "Mail Error: " . $mail->ErrorInfo;
            exit;
        }

        include ('mailconfirmation.php'); // text to say the email has been send

}

因此,此代碼發送包含激活碼(com代碼)的電子郵件。 電子郵件確認的代碼只是純文本,因此我省略了。

接下來要做的是將激活(通過提供的鏈接)設置為“是”。 這是執行此操作的代碼:

    include('configdb.php');
$passkey = $_GET['passkey'];
$sql = "UPDATE user SET com_code=NULL WHERE com_code='$passkey'";
$result = mysqli_query($conn,$sql) or die(mysqli_error());
if($result)
{
    echo '<div>Your account is now active. You may now <a href="indexresp.php">Log in</a></div>';
}
else
{
    echo "Some error occur.";
}
?>

因此,當通過if(連接)時,用戶將被重定向到索引,在該索引中,他可以使用自己的帳戶信息登錄,並且應該激活他的信息(通過更新)。 我認為問題出在這段代碼中,因為這里的sql變量由於某種原因不再更新com_code。

重定向后,我嘗試使用剛剛輸入的(應該是:已激活的)詳細信息登錄。

檢查登錄的代碼(檢查通行證和郵件是否有效)如下:

   session_start();
include('configdb.php');
if(isset($_POST['submit_login']))
{
    $email = trim($_POST['email']);
    $password = trim($_POST['password']);

    $result = mysqli_query($conn,"SELECT * FROM user WHERE email='$email' AND password='$password' AND com_code IS NULL"); // was password

    $num_row = mysqli_num_rows($result);
    $row=mysqli_fetch_array($result);
    if( $num_row ==1 )
    {
        $_SESSION['email']=$row['email']; 
        header("Location: member.php");
        exit;
    }
    else
    {


        include ('errorlogin.php');




    }
}

我希望你們中的一個可以幫助我解決這個問題,因為經過2個小時的搜索,對於我來說(現在)足夠了;)

抱歉,我的英語和代碼中的一些荷蘭語單詞(請嘗試翻譯一些)。

提前謝謝!

您的插入部分:

$sql2 = "INSERT INTO user ..."

從未在提供的代碼中使用。 也許您錯誤地刪除了SQL進程。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM