Click to See Complete Forum and Search --> : email verification


psylang
12-09-2004, 12:44 AM
anyone who knows how to send validation codes through email to verify their registration?

96turnerri
12-09-2004, 04:47 AM
//register.php
$rand = rand(1000, 100000);
$sql = "INSERT INTO `pending` (username, password, rand) VALUES ('$username', '$password', '$rand')";
mysql_query($sql) or die(mysql_error());
$to = $email;
$subject = "Email Very";
$headers = "Email Very <admin@domain.com>";
$msg = "Please Verify Your Email\n\nwww.domain.com/verify.php?id=$rand";
mail($to, $subject, $msg, $headers);

//verify.php
$sql = "SELECT * FROM pending WHERE rand = '".$_GET["id"]."'";
$result = mysql_query($sql) or die(mysql_error());
if(mysql_numrows($result) == 0) {
echo "Sorry Incorrect ID Inputed";
} else {
while($row = mysql_fetch_assoc($result)) {
foreach($row as $key => $val) {
$$key = $val;
}
}

$sql = "INSERT INTO users (username, password) VALUES ('$username', '$password')";
mysql_query($sql) or die(mysql_error());
echo "Thank You, Your Email Has Been Verified";
}

scragar
12-09-2004, 05:04 AM
you need to be carfull about using the random number function, what happens if two people share a random number?

PHP has a build in function what will sort that out:

$rand = uniqid() * 1.0;

96turnerri
12-09-2004, 05:15 AM
scagar has a point, although the chances on rand generating the same number between 1000 and 100000 are infintly small, there is still a chance, go with the uniqid()

psylang
12-09-2004, 07:37 PM
ei thanks guys!

that'll help a lot! but i'll be asking some questions again next time i get trouble with the codes. :)

psylang
12-09-2004, 08:11 PM
is pending another table?
so does that mean i need to have same fields for the pending records as where i am going to insert the verified record?

and how is it going to delete the record from pending whn the member has already verified it's email?

96turnerri
12-09-2004, 08:52 PM
pending is indetical to users, except has one additional field 'rand'

its doesnt delete, my bad
add
$sql = "DELETE FROM `pending` WHERE rand = '".$_GET["id"]."'";
mysql_query($sql) or die(mysql_error());
below

$sql = "INSERT INTO users (username, password) VALUES ('$username', '$password')";
mysql_query($sql) or die(mysql_error());

psylang
12-09-2004, 09:33 PM
what do u mean by this:
pending is indetical to users, except has one additional field 'rand'

i assumed it is a table bcoz i get an error message
DB Error: no such table

96turnerri
12-11-2004, 08:22 AM
you have to make these tables they dont make themselves

pending is indetical to users, except has one additional field 'rand' by that i mean "the table pending is indentical ie has the same fields as users, except it has one extra one called rand

eg

users
username|password|email
pending
username|password|email|rand

psylang
12-12-2004, 06:44 PM
i thought so.. thanks man :)
you're a big help. :cool:

psylang
12-12-2004, 09:23 PM
how bout a script for mailing list?

scragar
12-13-2004, 03:18 AM
$rs = mysql_query("SELECT email, username FROM users");
$numRes = mysql_num_rows($rs);
if($numRes == 0){
echo("no-one in mailing list,");
}else{
$i = 0;
while($i < $numRes){
mail(mysql_result($rs, i, "email"), "The latest mail.", "Hello ".mysql_result($rs, i, "username")."\n you have subscribed to the mailing list, and as such recived this email....", $headers);
$i++
};
echo("$i e-mails sent.");
};
?>

psylang
12-13-2004, 08:16 PM
oh thanks for the idea.
but i was thinking how i could automatically forward an email to the subcscribers in my mailing list by sending it using one email address. is that possible?

scragar
12-14-2004, 03:19 AM
replace $headers with "From: MyEmail@MySite.com"

psylang
12-15-2004, 12:34 AM
no the one that automatically forwards it to all the subscribers