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:
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) < 3 ){
$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();
}
}
}
?>
Comment