我需要在MySQL 創建隨機密鑰存儲如果我使用:如何創建隨機密鑰php mysql?
<?php echo md5(rand(10000,99999)); ?>
我在哪裏可以存儲它
<?php
require 'config.inc.php';
foreach($_POST as $k=>$v)
{
$_POST[$k] = trim($v);
}
if(!isset($_POST['produgg_username']) or !isset($_POST['produgg_password']) or !isset($_POST['produgg_email']))
{
print "Please use all fields";
}elseif(empty($_POST['produgg_username'])){
print "Please choose a username";
}elseif(empty($_POST['produgg_password'])){
print "Please choose a password";
}elseif(empty($_POST['produgg_email'])){
print "Please enter an email address";
}elseif(!filter_var($_POST['produgg_email'], FILTER_VALIDATE_EMAIL)) {
print "Please enter a valid email address";
}elseif(!preg_match("/^[a-z0-9]+$/i", $_POST['produgg_username'])) {
print "Please use only characters and numbers for username";
}elseif($usersClass->checkUserExists($_POST['produgg_username'])) {
print "Username Taken, please choose another";
}else{
if($usersClass->register($_POST['produgg_username'], md5($_POST['produgg_password']), $_POST['produgg_email']))
{
print "success";
$toemail = $_POST['produgg_email'];
$touser = $_POST['produgg_username'];
// Send activation email
$to = $toemail;
$subject = "Activation";
$headers = "From: [email protected]";
$body = "Howdy $touser!
To activate your please click on the following link - http://www..co.uk/activateuser.php?email=$toemail";
mail($to, $subject, $body, $headers);
}else{
print "Something weird happened and we couldn't setup the account!";
}
}
?>
在你的代碼中,你沒有存儲任何東西,對嗎? – hakre
向我們展示對象'$ userClass'的類的函數register()?另外,'md5(rand(10000,99999));'會生成一個隨機ID,但不能保證唯一性。如果你需要它是唯一的,你需要添加另一個變量,可能是'time()'。 – Shef