Results 1 to 2 of 2

Thread: How do I create, validate email form register.

  1. #1
    Join Date
    Feb 2008

    Question How do I create, validate email form register.

    Okay here is my code I have so far.

    PHP Code:

    //This code runs if the form has been submitted
    if (isset($_POST['submit'])) {

    //This makes sure they did not leave any fields blank
    if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) {
    'You did not complete all of the required fields');

    // checks if the username is in use
    if (!get_magic_quotes_gpc()) {
    $_POST['username'] = addslashes($_POST['username']);
    $usercheck $_POST['username'];
    $check mysql_query("SELECT username FROM users WHERE username = '$usercheck'")
    or die(
    $check2 mysql_num_rows($check);

    //if the name exists it gives an error
    if ($check2 != 0) {
    'Sorry, the username '.$_POST['username'].' is already in use.');

    // this makes sure both passwords entered match
    if ($_POST['pass'] != $_POST['pass2']) {
    'Your passwords did not match. ');

    // here we encrypt the password and add slashes if needed
    $_POST['pass'] = md5($_POST['pass']);
    if (!
    get_magic_quotes_gpc()) {
    $_POST['pass'] = addslashes($_POST['pass']);
    $_POST['username'] = addslashes($_POST['username']);

    // now we insert it into the database
    $insert "INSERT INTO users (username, password)
    VALUES ('"
    .$_POST['username']."', '".$_POST['pass']."')";
    $add_member mysql_query($insert);

    <p>Thank you, you have registered - you may now login</a>.</p>


    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <table border="0">
    <input type="text" name="username" maxlength="60">
    <input type="password" name="pass" maxlength="10">
    <tr><td>Confirm Password:</td><td>
    <input type="password" name="pass2" maxlength="10">
    <tr><th colspan=2><input type="submit" name="submit" value="Register"></th></tr> </table>

    This is what I want to learn to do: I want to learn how to be able to, when user registers asks them for their email and then they have to click a link to activate account.

    If you don't know what I mean please post. THanks Adeang.

  2. #2
    Join Date
    Aug 2006
    Well, you need to generate some sort of key that can't easily be replicated.

    For example, you might take the user's email address, and splice in some random word of your choosing, eg:


    would become..


    You could use 'specialkey' or anything you like, but it's important you use the same value every time.

    You would then run the above string (doug@specialkeyemail.com) through the md5 function, and this will generate a key. Then when you email the user, you would include a link to a script, and pass two values, email and key:

    validateuser.php?email=doug@email.com&key=(the md5 string)

    (Tip: Make sure you run the email address through the urlencode() function before using it in the url).

    In the validateuser.php script, you would take the incoming $_GET value of email (which in this case is doug@email.com), (Tip: If you used the urlencode() function on the email address, you'll need to use urldecode() to get it back to its proper lettering) and you would again splice your specialkey in to the email address, and run it through the md5 function.

    You then check to see if this value matches the incoming $_GET value of key.

    If they match, then you can validate the user's registration.
    Last edited by callumd; 10-21-2008 at 01:20 PM.
    Want web development tutorials that are clear and easy to understand?
    The Now I Get It blog.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center