Jump to content

Activation Code - PHP (:


Stotty

Recommended Posts

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
Share on other sites


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
Share on other sites

$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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.