Jump to content

Random generation number on submit button and send a mail to the user


Revs

Recommended Posts

Hi

 

         I have a registration page for a website, in that i want to generate random number to disable the person's profile. Here the random number should generate after he creates his profile and that should be sent to the person through mail. He should enter that number for disabling his profile. I want the sample code or script by which i can implement easily.

 

 

Thanks  in advance

Revs

Link to comment
Share on other sites

Yes this is possible. I doubt there is a simple drop in script for this. You are better of coding this yourself.
 
A simple way to set this up is in your users table you'll have to have two fields, activated and activate_code.  When the user signs up set the activated column to 0 and the activate_code column to store the random generated code.
 
You'd then email the person the random generated code. In the email provide the activate link like

http://yoursite.com/activate.php?code=$random_active_code&user_id=$users_id

 
When the user try to login you'll want to check if that the profile is activated. Example login code

if($result = mysql_query("SELECT user_id, activated, ..other columms... WHERE username='$username' AND password='$password'"))
{
    $row = mysql_fetch_assoc($result);
    if($row['activated'] == 1)
    {
        // user is actiavted and can login
    }
    else
    {
        // user is NOT actiavted. Tell them to activate account or resend the activation code
    }
}

 
 
Now for the user to activate theire account they must goto the link provided in the email. Example code for actiavte.php would be

<?php

// connect to database here
mysql_connect(db_host, db_user, db_pass);

// select database
mysql_select_db(db_name);

// check that the required data exits
// user id
// and the activation code
if(isset($_GET['code']) && isset($_GET['user_id']))
{
    $user_id = (int) $_GET['user_id'];                  // user id
    $code    = mysql_real_escape_string($_GET['code']); // activation code

    // update the users table, setting the profile to active and removing the activation code
    $query   = "UPDATE users_table SET activated = 1 && activate_code = NULL WHERE activate_code = '$code' && user_id='$user_id'";
    if($result = mysql_query($query))
    {
        if(mysql_affect_rows() == 1)
        {
             // display profile is now active message and user can login
        }
        else
        {
             // display error, the provided user_id or activate_code is invalid
        }
    }
    else
    {
         // Something wrong the query display an error message
    }
}
Edited by Ch0cu3r
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.