Jump to content

Email verification script * SOLVED


PigsHidePies

Recommended Posts

Hello, I have a working registration + login script but I want to to verify the registrant's email address before activating her account. I am wodering if someone would provide some sample code to achieve this effect. I want an email sent with a random activation code after someone registers and then the user must click a link in the email to activate the account or else they can't sign in. Any help is appreciated.
Link to comment
Share on other sites

// Create random number between 111,111 and 999,999
$randomID = rand(111111, 999999);

Create two new fields in your mysql database table one called "activated" and one called "activationID"

When they first create their account put in active as no, or 0 or whatever you prefer to show they aren't active. Then put their random ID into the database under activationID.

Then send them an email with a link like this:
http://www.yourdomain.com/activate.php?userid=39&activate=999999

Then make activate.php like this:

[code=php:0]
<?php

$userid = stripslashes($_GET["userid"]);
$activate = stripslashes($_GET["activate"]);

$query = mysql_query("SELECT * FROM `users_table` WHERE `id` = '$userid'") or die(mysql_error());
$code = mysql_fetch_array($query);
$activatecode = $code["activationID"];

if ($activatecode == $activate) {
      $activate = mysql_query("UPDATE `users_table` SET `active` = `yes`") or die(mysql_error());
      if(!$active) {
            echo "Problem with activating, see administrator";
      } else {
            echo "Thank you for activating your account!";
      }
} else {
    echo "Incorrect Userid or Activation Code";
}
?>
[/code]

Edit: I just tested this with my latest script and it works perfectly as planned.
Link to comment
Share on other sites

First off, thanks for your help . I'm new to php and can't get the activate.php page to function correctly.I added the extra rows in my database and when the user signs up it puts a 0 in the "active" column and the login script wont let anyone who doesn't have a 1 in that column log in. The activate page is the thing thats giving me trouble.I've been working on it for two hours now and I'm just stuck at this point. Heres what I got:

[code]
<?php

$uid = stripslashes($_GET['uid']);
$act = stripslashes($_GET['act']);

@ $db = new mysqli('localhost', 'username', 'password', 'database');

if (mysqli_connect_errno())
{
echo 'Error: Cannot connect to database.';
exit;
}

$checku = $db->query("select * from database where uid='$uid' ");

$checka = $db->query("select * from database where act='$act' ");


$code = $checkc->fetch_assoc();
$activatecode = ($code['act']);

if ($activatecode == $act) {
      $activate = $db->query("UPDATE `database` SET `active` = `1`")
or die(mysql_error());
      if(!$active) {
            echo "Problem with activating, see administrator";
      } else {
            echo "Thank you for activating your account!";
      }
} else {
    echo "Incorrect Userid or Activation Code";
}
?>
[/code]

Link to comment
Share on other sites

[b]sorry didnt see the post before were the member has done this for you, you will have to use the members code to see how it all works.[/b]

good luck.


all i done is make the activ set to 1 ok.

I also saw that your making your code block all errors, it is relly best you solve theose errors if they are there ok.

[code]
<?php

$uid = stripslashes($_GET['uid']);
$act = stripslashes($_GET['act']);

@ $db = new mysqli('localhost', 'username', 'password', 'database');

if (mysqli_connect_errno())
{
echo 'Error: Cannot connect to database.';
exit;
}

$checku = $db->query("select * from database where uid='$uid' ");

$checka = $db->query("select * from database where act='$act' ");


$code = $checkc->fetch_assoc();

$activatecode = ($code['act']);

if ($activatecode == $act) {

$activ="1";

      $activate = $db->query("UPDATE `database` SET `active` = `$activ`")
or die(mysql_error());
      if(!$active) {
             echo "Problem with activating, see administrator";
      } else {
             echo "Thank you for activating your account!";
      }
} else {
    echo "Incorrect Userid or Activation Code";
}
?>
[/code]
Link to comment
Share on other sites

I replied due to the fact that copying and pasting the above code did not work for me. After some messing around I have gotten it down to one line that isn't working. On line 11 I am getting an error saying "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/act.php on line 11"
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.