| PHP, MySQL General PHP questions. Or go to our PHPsuexec Forum >> |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread |
|
|
#1 (permalink) |
|
I own you!
Excelling Contributor
Joined in Apr 2004
563 posts
Gave thanks: 0
Thanked 3 times
|
Email Verification
What I want to do is pretty the same thing as vBulletin does: Once a user signs up, he is sent an email, with a link to click and activate the account, or do something else.
I heard it isn't hard to do. Do you guyz know of any tutorials out there that explain how to do that? Thanks. |
|
|
|
|
|
#2 (permalink) |
|
the one who was
Super #1
Joined in Jul 2003
Lives in Memphis
1,967 posts
Gave thanks: 0
Thanked 3 times
|
What I like to do is generate a random password for the user and send that to them in email. Once they get their email, they can login and change their password. This is the most simple and easiest way to do it. Everytime a user logs in, I then check a field in the database for that account to see if they have logged in before. If they haven't, I update the DB to reflect that they have logged in and are "verified". That way I can distinguish between active and inactive accounts.
Code:
function makePassword() {
$salt = str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789");
srand((double)microtime()*1000000);
$i = 0;
while ($i <= 8) {
$num = rand() % 33;
$tmp = substr($salt, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
Code:
$randomPass = makePassword(); ![]()
__________________
Patrick Warnings: The program(s) might crash unexpectedly or behave otherwise strangely. (But of course, so do many commercial programs on Windows.) --www.gimp.org |
|
|
|
|
|
#3 (permalink) |
|
I own you!
Excelling Contributor
Joined in Apr 2004
563 posts
Gave thanks: 0
Thanked 3 times
|
thanks Patrick,
So that code would generate an 8 character long password correct? Another question on your code. I would like to store the pass in the db as an md5 encrypted password. So would I just write something like his? PHP Code:
Thanks again |
|
|
|
|
|
#4 (permalink) |
|
the one who was
Super #1
Joined in Jul 2003
Lives in Memphis
1,967 posts
Gave thanks: 0
Thanked 3 times
|
Yes, that looks correct. Of course, this is a sampling of some code from one of my real time sites:
Code:
$arHold = array();
$result = mysql_query("DESCRIBE table");
while ($row = mysql_fetch_assoc($result)) {
$arHold[$row["Field"]] = NULL;
}
// Make the update query that inserts the user into the table.
$queryAdd = "INSERT INTO table SET ";
foreach ($_POST as $key => $value) {
if (array_key_exists($key, $arHold)) {
$value = addslashes($value);
$queryAdd .= "$key='$value', ";
}
}
$queryAdd = substr($queryAdd, 0, -2); // Strip off the trailing comma and space
$randomPass = makePassword();
$queryAdd .= ", l_password='" . md5($randomPass) . "'";
$result = mysql_query($queryAdd);
if ($result) {
// Generate a welcome page with further instructions. Also generate the welcome email as well.
sendWelcomeEmail();
} else {
// Email error message to the me.
echo "<p>Sorry, there was an error setting up your account. Details have been logged for the site administrator. Feel free to email me with your information and we shall set this account up for you manually</p>";
}
__________________
Patrick Warnings: The program(s) might crash unexpectedly or behave otherwise strangely. (But of course, so do many commercial programs on Windows.) --www.gimp.org |
|
|
|
|
|
#5 (permalink) |
|
I own you!
Excelling Contributor
Joined in Apr 2004
563 posts
Gave thanks: 0
Thanked 3 times
|
hmm not sure why it doesn't send that email.
here is what I have: PHP Code:
Then I have the function of the email itself: PHP Code:
So now I have this: PHP Code:
Now the query gets added to the db fine (I can see the row in phpmyadmin), but it does not send the email. What am I doing wrong? Thanks |
|
|
|
|
|
#6 (permalink) |
|
the one who was
Super #1
Joined in Jul 2003
Lives in Memphis
1,967 posts
Gave thanks: 0
Thanked 3 times
|
Code:
function sendWelcomeEmail($sendEmail){
__________________
Patrick Warnings: The program(s) might crash unexpectedly or behave otherwise strangely. (But of course, so do many commercial programs on Windows.) --www.gimp.org |
|
|
|