Nov 25, 2009

Activation Code

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Scripting > PHP

Activation Code

khalilov
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

Comment/Reply (w/o sign-up)

toby
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.

Comment/Reply (w/o sign-up)

yordan
QUOTE(khalilov @ Aug 1 2008, 11:58 AM) *
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. huh.gif

Comment/Reply (w/o sign-up)

pyost
QUOTE(toby @ Aug 1 2008, 04:05 PM) *
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 laugh.gif

 

 

 


Comment/Reply (w/o sign-up)

TavoxPeru
QUOTE(khalilov @ Aug 1 2008, 04:58 AM) *
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,

Comment/Reply (w/o sign-up)

khalilov
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 :/

Comment/Reply (w/o sign-up)

Mordent
Linky

Tadaa! I'll leave it to someone else to expand on that, as I haven't the time. Hope that helps, however.

Comment/Reply (w/o sign-up)

TavoxPeru
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,

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : activation, code

  1. Php Random Selector
    whats the code (2)
  2. Dynamic Php Image And Better Php Code Question
    (10)
    Im working on a dynamic image, can i put 2 images in same dynamic image, and can i make this code
    shorter? if ( $goal == 31 ) { $xp2 = ('14833'); } elseif ( $goal == 32 ) { $xp2 =
    ('16456'); } elseif ( $goal == 33 ) { $xp2 = ('18247'); } elseif ( $goal == 34 ) {
    $xp2 = ('20224'); } elseif ( $goal == 35 ) { $xp2 = ('22406'); } elseif ( $goal ==
    36 ) { $xp2 = ('24815'); } elseif ( $goal == 37 ) { $xp2 = ('27473'); } elseif (
    $goal == 38 ) { $xp2 = ('30408'); } elseif ( $goal == 39 ) { $xp2 = ('33648')....
  3. What's Wrong With My Php Webpage?
    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
    somthing wrong. Where did I write by mistake? CODE include('data/workinfo/0.php');
    $viewwork = substr($work ,0,249); /* HERE CAN'T WORK WELL! */ $newthread =
    fopen("http://c8s2007.freetzi.com/bbs/new.php?action=article&digest=0&postdate=0&author=1&fname=0&hi
    ts=0&replies=1&pre=6&num=10&length=35&order=1", "rb"); if(!$newthread){         $newthread =
    "无法调用信息!";     }else{         $ad = "
    ";      ....
  4. Code Snippets Repository
    (0)
    Well as everybody know in these forums people posts a lot of code snippets that could be organized
    in a simple page or whatever, my question is if someone is interested to do it or if exists
    something like that here at astahost. I think it would be very helpful for everybody as well to
    keep things more organized. Best regards,....
  5. How Can I Write PHP Code By This Formmail Html
    (5)
    purpose is i want the information in the web page sent into my email. i just know that i need to use
    php script to operate this action ,but i have no idea about this php code. so anyone can help me
    please... thank you very much. ชื่อ
    ....................... ....... นามสกุล
    ....... ชื่อเล่น
    วันเกิด 1 2 3 4 5 6 7 8 9 10 11
    12 13 14 15 16 ....
  6. [PHP + MySQL] Separating The Results By Pages
    Simple code (0)
    Hi! I will post here a code for separating the results of MySQL in pages. You ask: Why separete? I
    answer: Imagin that you have 1523 results to display. I dont have to say anything. =P Here is it.
    ------------------------------------------------------------------- CODE $conect =
    mysql_connect("host","user","password"); $select_db = mysql_select_db("database"); $query = "SELECT
    * FROM mytable"; $results = "15"; //Number of results displayed per page. if (!$page) {
        $counter = "1"; } else {     $pcounter = $page; } $start = $counter - 1; $start = $counter *
    $resu....
  7. What's Wrong With This Preg_replace Code?
    (2)
    I have written a JavaScript that prompts auser for 5 table attributes for entry into the posting
    area and it produces this: It is then passed through this preg_replace for display in the
    preview or as a submission in a post: CODE $txt = preg_replace( "#\ (.+?)\ #is", " \\6 ", $txt
    ); What it produces however is this: CODE When what I want is this: CODE
    What is it that is wrong with this code and giving this odd unwanted result? Help would be most
    certainly appreciated because I am tired of looking at it, my eyes are getting crossed ....
  8. Any Tool/software For Php Code Generation ?
    Tool for code generator (3)
    Where find any tool to generate PHP class?....
  9. How To Use Cookie In Your Web Site ?
    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
    cookies? becouse the cookies it like the header you can not send it after any output wes sent so
    you must send the cookies before any output like as ,echo and any other code i well make an E.X.
    to use the cookies you must have 2 file index.php update.php ---------- in the index.php add this
    code CODE    // This section must go at the top of the page that will display    // the
    users favorites.  These are the 'default' URLs that the user    // will se....
  10. Php Reading And Writing To File
    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
    use CODE $fp = fopen ("file.txt", "r"); $bytes = 4; $buffer = fread($fp, $bytes); fclose
    ($fp); print $buffer; ------------------- to write to same file CODE $fp = fopen
    ("file.txt", "w+"); fwrite ($fp, "Test"); fclose ($fp); ---------------- thanks and iwait the
    commant....
  11. Page Doesn't Load When This Php Code Is Present ?
    (6)
    CODE switch($_GET ) {   case "home";      include("index.php");   break;   case
    "gallery";      include("gallery.php");   break;     case "links";      include("links.php");
      break;   case "guestbook";      include("../guestbook/");   break;   case "portfolio";  
       include("portfoilio.php");   break;   case "other";      include("other.php");   break;
      case "about";      include("about.php");   break;   case "contact";    
     include("contact.php");   break;   case "login";      include("/private/");   break;  
    default:....

    1. Looking for activation, code

See Also,

*SIMILAR VIDEOS*
Searching Video's for activation, code
advertisement



Activation Code

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com