您好我正在尝试在php中制作电子邮件激活脚本,您在上面看到的内容(2aad888f2b4ac316b016a9a0bda1c329)是此用户唯一的激活密钥。您认为问题是什么? 这是我的新代码:
<?php
$host="localhost";
$username="root";
$password="power1";
$db_name="members";
$tbl_name="users";
$link = mysql_connect($host, $username, $password)or die("cannot connect. Please contact us");
mysql_select_db($db_name)or die("cannot select DB. Please contact us");
$queryString = $_SERVER['QUERY_STRING'];
if(isset($_SESSION[$queryString])) {
$query = "SELECT * FROM users WHERE email='$_SESSION[$queryString]'";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
if ($queryString == $row[activationkey]){
echo "Congratulations! You have succesfully activated you account. You may now login.";
$sql = ("UPDATE users SET activationkey='' AND status='activated' WHERE username=".$row['username']);
if (!mysql_query($sql)) {
die('Error: ' . mysql_error());
}
}
}
}
?>
答案 0 :(得分:1)
$_SESSION['2aad888f2b4ac316b016a9a0bda1c329']
不存在。“但是不能存在,因为密钥并不总是存在那些密钥是随机的”
然后你的错误出现在这一行,无论如何都试图访问该密钥:
$uemail = $_SESSION["$queryString"];
也许您需要在访问密钥之前检查密钥是否确实存在,或者在程序逻辑中更改某些内容以防止出现这种情况。
答案 1 :(得分:-1)
$host="localhost";
$username="root";
$password="power1";
$db_name="members";
$tbl_name="users";
$link = mysql_connect($host, $username, $password)or die("cannot connect. Please contact us");
mysql_select_db($db_name)or die("cannot select DB. Please contact us");
$queryString = $_SERVER['QUERY_STRING'];
if(isset($_SESSION["$queryString")) {
$query = "SELECT * FROM users WHERE email='$_SESSION["$queryString"]'";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
if ($queryString == $row[activationkey]){
echo "Congratulations! You have succesfully activated you account. You may now login.";
$sql = ("UPDATE users SET activationkey='' AND status='activated' WHERE username=".$row['username']);
if (!mysql_query($sql)) {
die('Error: ' . mysql_error());
}
}
}
}