所以几个月前我在我的注册表上使用了一个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代码)的电子邮件。电子邮件确认的代码只是纯文本,所以我把它留了出来。
下一步是将激活(使用提供的链接)设置为yes。这是执行此操作的代码:
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小时后搜索(现在)对我来说足够了;)
对不起我的英语和代码中的一些荷兰语单词(试着翻译一些)。
提前谢谢!答案 0 :(得分:0)
您的插入部分:
$sql2 = "INSERT INTO user ..."
从未在提供的代码中使用过。也许你错误地删除了SQL进程。