Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2011
    Posts
    43
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Question Email account activation help needed.

    I am building a site that requires users to create an account before they can access other pages. Building the new account creation and login was easy enough. The next thing I want to do is make it so my users have to click an activation link sent to their email to activate their account.

    I am able to use PHP to automatically generate an email to the user, but I just don't know how to make an activate.php page that would check the $active value and id from the URL, then set the active field value in the database to 'active'


    Here is my code so far:

    PHP Code:
    <?

    $active 
    md5(uniqid(rand(), true)); 

    $userid=$_POST['userid'];
    $password=$_POST['password'];
    $password2=$_POST['password2'];
    $agree=$_POST['agree'];
    $todo=$_POST['todo'];
    $email=$_POST['email'];
    $name=$_POST['name'];
    $phone=$_POST['phone'];




    if(isset(
    $todo) and $todo=="post"){

    $status "OK";
    $msg="";

    // if userid is less than 3 char then status is not ok
    if(!isset($userid) or strlen($userid) <3){
    $msg=$msg."User id should be =3 or more than 3 char length<BR>";
    $status"NOTOK";}                    

    if(
    mysql_num_rows(mysql_query("SELECT userid FROM plus_signup WHERE userid = '$userid'"))){
    $msg=$msg."Userid already exists. Please try another one<BR>";
    $status"NOTOK";}                    

    if(
    mysql_num_rows(mysql_query("SELECT email FROM plus_signup WHERE email = '$email'"))){
    $msg=$msg."Email already exists. Please try another one<BR>";
    $status"NOTOK";}        

    if ( 
    strlen($password) < ){
    $msg=$msg."Password must be more than 3 char length<BR>";
    $status"NOTOK";}                    

    if ( 
    $password <> $password2 ){
    $msg=$msg."Both passwords are not matching<BR>";
    $status"NOTOK";}        

    if ( 
    strlen($phone) < 10 ) {
    $msg=$msg"Phone Number must be 10 digits<BR>";
    $status"NOTOK";}        


    if (
    $agree<>"yes") {
    $msg=$msg."You must agree to terms and conditions<BR>";
    $status"NOTOK";}    

    if(
    $status<>"OK"){
    echo 
    "<font face='Verdana' size='2' color=red>$msg</font><br><input type='button' value='Retry' onClick='history.go(-1)'>";
    }else{
    if(
    mysql_query("insert into plus_signup(userid,password,email,name,phone,active) values('$userid','$password','$email','$name','$phone','$active')")){
    mail($_POST['email'], 'User Registration''Click here to activate your account: http://www.myExample.com/activate.php?u=' mysql_insert_id() . '&c=' $active); 
    echo 
    "<font face='Verdana' size='2' color=green>Welcome, You have successfully signed up.  <br><br>In order to view content, you must first follow the activation link we sent to your email.<br></font>";
    echo 
    "<font face='Verdana' size='2' color=red>$msg</font><br><input type='button' value='Login' onClick='history.go(-2)'>";}
    else{ echo 
    "Database Problem, please contact Site admin";

    //echo mysql_error();

    }

    }
    }
    ?>

  • #2
    Regular Coder
    Join Date
    Sep 2008
    Posts
    697
    Thanks
    8
    Thanked 17 Times in 16 Posts
    Use this tutorial: http://www.learnphponline.com/script...-for-php-forms

    First create a database columns with these like information.

    Code:
     
    `status` varchar(20) NOT NULL,
     `activationkey` varchar(100) NOT NULL,
    UNIQUE KEY `activationkey` (`activationkey`)
    The status would be 1 or 0, 1 for active 0 for inactive/not activated.

    Code:
    $queryString = $_SERVER['QUERY_STRING'];
    
    $query = "SELECT * FROM users";
    
    $result = mysql_query($query) or die(mysql_error());
    
      while($row = mysql_fetch_array($result)){
    
        if ($queryString == $row["activationkey"]){
    
           echo "Congratulations!" . $row["username"] . " is now the proud new owner of a YOURWEBSITE.com account.";
    
           $sql="UPDATE users SET activationkey = '', status='activated' WHERE (id = $row[id])";
    
           if (!mysql_query($sql))
    
      {
    
            die('Error: ' . mysql_error());
    
      }
    
        }
    
      }
    You can use the GET function.
    MY MSN: Sith717@Hotmail.com
    PHP, HTML, and CSS Coding, Logo and Web Design - Professionally done.
    PM me anytime for HTML, PHP or web design help. I will be glad to help you out.


  •  

    Posting Permissions

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