Revs Posted October 17, 2013 Share Posted October 17, 2013 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 Quote Link to comment Share on other sites More sharing options...
Barand Posted October 17, 2013 Share Posted October 17, 2013 Have you tried leaving money under your pillow to see if the Code Fairy leaves some? If that fails, try freelance section of the forum. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 17, 2013 Share Posted October 17, 2013 (edited) 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 October 17, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.