1 回答
TA贡献1805条经验 获得超10个赞
$_SESSION[""] 变量是全局变量。我以前不知道,但我现在知道了。我刚刚为每个注册的用户分配了每个变量。
<!DOCTYPE HTML>
<html>
<head>
<style>
body {
text-align: center;
font-family: sans-serif;
}
a {
text-decoration: none;
color: blue;
}
#logout {
margin: 0 auto;
text-align: center;
border: 1px solid;
border-radius: 5px;
max-width:1024px;;
height: 800px;
}
</style>
</head>
<body>
<div id="logout">
<?php
session_start();
/* Sends an email to the user and adds the special key to another database */
$username = $_GET['username']; /* Gets the username that was submitted in the HTML form. */
$password = $_GET['password']; /* Gets the password that was submitted in the HTML form. */
$email = $_GET['email']; /* Gets the email that was submitted in the HTML form. */
$servername = "localhost"; /* MySQL database. Change if needed! Most of the time its not localhost unless you're hosting on your computer. */
$user = 'xxxx'; /* MySQL username. Change if needed. */
$pass = 'xxxx'; /* MySQL password. Change if needed. */
$dbname = 'vibemcform'; /* MySQL database name. Change if needed. */
$bytes = random_bytes(10); /* Randomized code */
$key = bin2hex($bytes); /* Makes the randomized code */
$con = new mysqli($servername, $user, $pass, $dbname); /* Connects to the database */
$query = mysqli_query($con, "SELECT * FROM `data` WHERE USERNAME='".$username."'"); /* Gets the username that was submitted */
$hash = password_hash($password, PASSWORD_DEFAULT);
$_SESSION['hash'] = $hash;
$_SESSION['password_not'] = $password;
if (mysqli_num_rows($query) > 0) { /* If the username exists... */
echo "ERROR: Username already exists. Please try signing up again.";
$con -> close();
exit;
} else { /* If the username DOESN'T exist... */
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $user, $pass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO dont (STR, USERNAME, PASSWORD, EMAIL)
VALUES ('$key', '$username', '$hash', '$email')"; /* Insert all the data to the database */
$conn->exec($sql);
}
catch(PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
}
}
$conn = null;
$msg = "localhost/vibemcform/verify.php?str=". $key . " Please verify your email!";
$msg = wordwrap($msg,70);
/*
$headers = array("From: xp10d363@gmail.com",
"X-Mailer: PHP/" . PHP_VERSION
);
*/
if (mail($email,"Verify your email",$msg/*, $headers*/)) {
echo 'Message accepted to your email address! Check your email to verify your account.';
} else {
echo 'Message not sent to your email. Contact the owner of the website!';
}
exit;
?>
<a href="index.html">Home</a>
</div>
</body>
</html>
- 1 回答
- 0 关注
- 135 浏览
添加回答
举报