Jump to content


Photo

Email verification script * SOLVED


  • Please log in to reply
6 replies to this topic

#1 PigsHidePies

PigsHidePies
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 10 September 2006 - 02:36 AM

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.

#2 tleisher

tleisher
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 10 September 2006 - 04:14 AM

// 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.yourdomai...activate=999999

Then make activate.php like this:

<?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";
}
?>

Edit: I just tested this with my latest script and it works perfectly as planned.

#3 PigsHidePies

PigsHidePies
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 10 September 2006 - 07:41 AM

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:

<?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";
}
?>



#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 10 September 2006 - 09:13 AM

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.

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.

<?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";
}
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 PigsHidePies

PigsHidePies
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 10 September 2006 - 09:51 AM

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"


#6 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 10 September 2006 - 10:53 AM

are you using session becose i dont see session_start();
at the top of the page.

if you are using sessions you must have session start at the top of all pages.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#7 PigsHidePies

PigsHidePies
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 10 September 2006 - 11:05 AM

I did it!  wow I blew a lot of time on this....so tired..thanks for your help tleisher and redarrow(again).




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users