| | Whats the php function that generates a random activation code then sends it to the email the user used to sign up. Also how do you check if the inputed email has corrected format? meaning its xxx@something.com |
| Nov 25, 2009 |
You could do something like a salted hash for the checking address, and regex (preg match) for checking email, though this is probably better done in javascript.
Also how do you check if the inputed email has corrected format? meaning its xxx@something.com there are functions in the mail syntax for testing if the address is valid. Returns "true" if the address is valid, and "false" if the address is not valid. Unfortunately I don't know these functions for php, you will have to read the php documentation for that. But this feature is inside all the mailer servers and the mailer clients, so you simply have to find it for php. You could do something like a salted hash for the checking address, and regex (preg match) for checking email, though this is probably better done in javascript. If you eventually decide on using JavaScript to validate user input, never forget that it can easily be bypassed! JavaScript can make your web site more user-friendly, but server-side verification, through PHP, is absolutely necessary. There are numerous functions that validate e-mail addresses, and you will have to find the one that you find the best. I've bumped into this one: http://www.phpit.net/code/valid-email/. If you use PHP5 (or so it seems), you can use an in-built PHP filter: http://www.w3schools.com/php/filter_validate_email.asp As for the validation string, it can really be anything... You can combine time() with a randomly generated number, and then md5() it
Whats the php function that generates a random activation code then sends it to the email the user used to sign up. Also how do you check if the inputed email has corrected format? meaning its xxx@something.com You have a lot of choices for the first one, the following code is a very simple function that i use: CODE <?php /** * Generate an activation code * @param int $length is the length of the activation code to generate * @return string */ function generateCode($length = 10) { $password=""; $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; srand((double)microtime()*1000000); for ($i=0; $i<$length; $i++) { $password .= substr ($chars, rand() % strlen($chars), 1); } return $password; } ?> For the second one, you can use the is_valid_email() function to verify the format of any email, also, i strongly recommend you to review the following topic Preventing Spam When Using Php's Mail Function because there you can find a complete review of this and the original article where i got the code. CODE <?php function is_valid_email($email) { return preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s]+\.+[a-z]{2,6}))$#si', $email); } ?> Other topics that i think can be helpul:Best regards,
k i got the email verification (got both java and php) and the random code generator, but i still don't know how to auto-email it :/
Linky
Tadaa! I'll leave it to someone else to expand on that, as I haven't the time. Hope that helps, however.
While searching my pc for some code that i need i found this two php functions that you can use, the first one for generating your activation code and the second for validate email addresses.
generatePassword(): With this function you can set the length and strength of the generated password. CODE <?php function generatePassword($length=9, $strength=0) { $vowels = 'aeuy'; $consonants = 'bdghjmnpqrstvz'; if ($strength & 1) { $consonants .= 'BDGHJLMNPQRSTVWXZ'; } if ($strength & 2) { $vowels .= "AEUY"; } if ($strength & 4) { $consonants .= '23456789'; } if ($strength & 8) { $consonants .= '@#$%'; } $password = ''; $alt = time() % 2; for ($i = 0; $i < $length; $i++) { if ($alt == 1) { $password .= $consonants[(rand() % strlen($consonants))]; $alt = 0; } else { $password .= $vowels[(rand() % strlen($vowels))]; $alt = 1; } } return $password; } ?> isValidEmail(): Simple case-insensitive regular expression for email validation that returns TRUE if valid and FALSE if not. CODE <?php function isValidEmail($email){ return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email); } ?> Best regards,
Similar Topics
Keywords : activation, code
(10) Im working on a dynamic image, can i put 2 images in same dynamic image, and can i make this code there may be something wrong in my php code. (2) This is the first time I use the functions fopen() and preg_replace() . It seems that there's (0) Well as everybody know in these forums people posts a lot of code snippets that could be organized (5) purpose is i want the information in the web page sent into my email. i just know that i need to use Simple code (0) Hi! I will post here a code for separating the results of MySQL in pages. You ask: Why separete? I (2) I have written a JavaScript that prompts auser for 5 table attributes for entry into the posting Tool for code generator (3) Where find any tool to generate PHP class?.... this semple code to use and get cookie (1) what is the cookie ? the cookis it is some info sent and save in user computer whare i can use the the code is very esay (4) this code to Read from file you can use this code in to make a small data base and it is very to (6) CODE switch($_GET ) { case "home"; include("index.php"); break; case Looking for activation, code
|
![]() Activation Code |
Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com