Stotty Posted May 19, 2009 Share Posted May 19, 2009 Ive made a register page and it emails a activation code $activ_code = rand(1000,9999); $server = $_SERVER['HTTP_HOST']; $host = ereg_replace('www.','',$server); mysql_query("INSERT INTO users (`user_email`,`user_pwd`,`country`,`joined`,`activation_code`,`full_name`) VALUES ('$_POST[email]','$md5pass','$_POST[country]',now(),'$activ_code','$_POST[full_name]')") or die(mysql_error()); $message = "Thank you for registering an account with $server. Here are the login details...\n\n User Email: $_POST[email] \n Password: $_POST[pass2] \n Activation Code: $activ_code \n ____________________________________________ *** ACTIVATION LINK ***** \n Activation Link: http://$server/activate.php?usr=$_POST[email]&code=$activ_code \n\n _____________________________________________ Thank you. This is an automated response. PLEASE DO NOT REPLY. "; ATM : the code is 4 letters so anything from 0000 to - 9999 random So output is Your activation code is : 8989 i want it to look more pro and send out Your activation code is 1089-8778-9090-8787 Thanks In advanced Stotty Link to comment https://forums.phpfreaks.com/topic/158758-activation-code-php/ Share on other sites More sharing options...
JD* Posted May 19, 2009 Share Posted May 19, 2009 for($i=0;$i < 4; $i++) { $activ_code.= rand(1000,9999).($i < 4 ? "-" : '"); } That will loop through four times, generate a random number (*make sure you look up how to really make this more random*) and then add a "-" between the number so long as we're not over 4 loops Link to comment https://forums.phpfreaks.com/topic/158758-activation-code-php/#findComment-837426 Share on other sites More sharing options...
Ken2k7 Posted May 20, 2009 Share Posted May 20, 2009 $i = 0; $activ_code = ''; while (++$i < 5) $activ_code .= rand(1000, 9999) . '-'; $activ_code = rtrim($activ_code, '-'); OR $i = 0; $activ_code = array(); while (++$i < 5) $activ_code[] = rand(1000, 9999); $activ_code = implode('-', $activ_code); Link to comment https://forums.phpfreaks.com/topic/158758-activation-code-php/#findComment-838350 Share on other sites More sharing options...
Stotty Posted May 20, 2009 Author Share Posted May 20, 2009 Thanks KEV after using that code in the email it send the write code 7787-8880-9990-9989 but in the database its still imputting 2456 a 4 numbered one How can i fix this $i = 0; $activ_code = array(); while (++$i < 5) $activ_code[] = rand(1000, 9999); $activ_code = implode('-', $activ_code); $server = $_SERVER['HTTP_HOST']; $host = ereg_replace('www.','',$server); mysql_query("INSERT INTO users (`user_email`,`user_pwd`,`country`,`joined`,`activation_code`,`full_name`) VALUES ('$_POST[email]','$md5pass','$_POST[country]',now(),'$activ_code','$_POST[full_name]')") or die(mysql_error()); Imputting into the database code is "INSERT INTO users (`user_email`,`user_pwd`,`country`,`joined`,`activation_code`,`full_name`) VALUES ('$_POST[email]','$md5pass','$_POST[country]',now(),'$activ_code','$_POST[full_name]')") or die(mysql_error()); Thanks Link to comment https://forums.phpfreaks.com/topic/158758-activation-code-php/#findComment-838352 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.