10 Replies - 712 Views - Last Post: 03 June 2009 - 11:31 PM Rate Topic: -----

#1 ninethousandfeet@msn.com  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 310
  • Joined: 09-February 09

how do you make a link that activates the user?

Post icon  Posted 03 June 2009 - 09:31 PM

hi,

i currently send my users an activation email that contains a random number. they are required to click on a link to activate, enter this random number in an UPDATE form, then they are taken to the login page where they can enjoy, etc. etc.

i notice that a lot of sites just send you a link and all you have to do is click it and it activates your account. this would eliminate one step for my users, which is great, but i have no idea how to do it.

here is my current registration page that sends out the email to activate, if you need to see the actual activation page let me know but again it is just a simple UPDATE $_GET form that when the activation number is matched, the userTable is updated and 'status' is switched from 'no' to 'activated'...
  if (!$error) {
  $activationkey =  mt_rand();
  $insertSQL = sprintf("INSERT INTO userTable (post_id, username, password, register_date, email, activationkey, status) VALUES (%s, %s, %s, %s, %s, '$activationkey', 'no')",
			   GetSQLValueString($_SESSION['post'], "int"),
					   GetSQLValueString($_POST['username'], "text"),
					   GetSQLValueString($_POST['password'], "text"),
					   GetSQLValueString($_POST['register_date'], "defined", 'NOW()'),
					   GetSQLValueString($_POST['email'], "text"),
			   GetSQLValueString($_POST['activationkey'], "text"),
			   GetSQLValueString($_POST['status'], "text"));

  mysql_select_db($database_connUser, $connUser);
  $Result1 = mysql_query($insertSQL, $connUser);
  
  $insertGoTo = "ThankYou.php";
  if (isset($_SERVER['QUERY_STRING'])) {
	$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
	$insertGoTo .= $_SERVER['QUERY_STRING'];
  }

$username = $_POST['username'];
$_SESSION['MM_Username'] = $username;
$to = $_POST['email'];
$subject = "Welcome!";
$headers  = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/plain; charset=UTF-8" . "\r\n";
$headers .= "From: mysite <me@mysite.com>" . "\r\n";
$message = "Welcome, $username!

Your activation number is $activationkey.
Click this link and enter the activation code above to complete registration.
";
  mail($to, $subject, $message, $headers);
  header(sprintf("Location: %s", $insertGoTo));
  }
  }
}



Is This A Good Question/Topic? 0
  • +

Replies To: how do you make a link that activates the user?

#2 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5234
  • View blog
  • Posts: 27,025
  • Joined: 10-May 07

Re: how do you make a link that activates the user?

Posted 03 June 2009 - 09:38 PM

Add a column to the database for "Activated" & set it to zero. Add another column to the database for "activation code". Make a random code at the time of registration, & fill the activation code database entry with that value. Then when you send the email, send the link of activation.php?activation_code="database value"&userid=""

Then when they click on it, pull the values in through php :

if($_GET['activation_code'] == "value from database") {
  update "table" set activated='1' where userid=$_GET['userid']
}



Properly validate all get variables 1st :)
Was This Post Helpful? 0
  • +
  • -

#3 ninethousandfeet@msn.com  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 310
  • Joined: 09-February 09

Re: how do you make a link that activates the user?

Posted 03 June 2009 - 10:55 PM

great! only thing i'm a little fuzzy on is how i get the value from the database in that conditional statement? right now, i have this and it isn't updating the table.
 if (($_GET['activationkey']) == ($row_getUser['activationkey'])) {
   "UPDATE userTable SET status='activated' WHERE user_id=%s";
  }



my two fields in the db are activationkey(the random number) AND status(originally 'no', but changed to 'activated' when this is done right)

any ideas what i'm doing wrong? do you need to see more of my code?
Was This Post Helpful? 0
  • +
  • -

#4 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: how do you make a link that activates the user?

Posted 03 June 2009 - 11:01 PM

try this:
if (($_GET['activationkey']) == ($row_getUser['activationkey'])) {
$strQuery =	"UPDATE userTable SET status='activated' WHERE user_id=".$_SESSION['post'];
mysql_query($strQuery) or die(mysql_error());

Was This Post Helpful? 0
  • +
  • -

#5 ninethousandfeet@msn.com  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 310
  • Joined: 09-February 09

Re: how do you make a link that activates the user?

Posted 03 June 2009 - 11:13 PM

did you mean to put the $_SESSION... in there?

this doesn't actually involve the $_SESSION['post'].

so, this is the link that goes out in the email, is this right so far?
http://www.mysite.com/activate.php?activationkey='$activationkey'&user_id='$user_id'


then, this is my code on the activation page...
$colname_getUser = "-1";
if (isset($_GET['activationkey'])) {
  $colname_getUser = $_GET['activationkey'];
}
mysql_select_db($database_connUser, $connUser);
$query_getUser = sprintf("SELECT user_id, username, activationkey, status FROM userTable WHERE activationkey = %s", GetSQLValueString($colname_getUser, "text"));
$getUser = mysql_query($query_getUser, $connUser) or die(mysql_error());
$row_getUser = mysql_fetch_assoc($getUser);
$totalRows_getUser = mysql_num_rows($getUser);

$userid = $_GET['user_id'];
if (($_GET['activationkey']) == ($row_getUser['activationkey'])) {
$strQuery =	"UPDATE userTable SET status='activated' WHERE user_id=$userid";
mysql_query($strQuery) or die(mysql_error());
}



with your previous solution and the slight variation i have above, i get this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Was This Post Helpful? 0
  • +
  • -

#6 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5234
  • View blog
  • Posts: 27,025
  • Joined: 10-May 07

Re: how do you make a link that activates the user?

Posted 03 June 2009 - 11:15 PM

Add single quotes around $userid
$strQuery =	"UPDATE userTable SET status='activated' WHERE user_id='".$userid."'";


Was This Post Helpful? 1
  • +
  • -

#7 ninethousandfeet@msn.com  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 310
  • Joined: 09-February 09

Re: how do you make a link that activates the user?

Posted 03 June 2009 - 11:22 PM

k, no error now, but it isn't updated the field in the db. is there something wrong with my sql? or something with the beginning of the conditional statement? i have it using $row_getUser['activationkey'].. is that incorrect?
$colname_getUser = "-1";
if (isset($_GET['activationkey'])) {
  $colname_getUser = $_GET['activationkey'];
}
mysql_select_db($database_connUser, $connUser);
$query_getUser = sprintf("SELECT user_id, username, activationkey, status FROM userTable WHERE activationkey = %s", GetSQLValueString($colname_getUser, "text"));
$getUser = mysql_query($query_getUser, $connUser) or die(mysql_error());
$row_getUser = mysql_fetch_assoc($getUser);
$totalRows_getUser = mysql_num_rows($getUser);

$user_id = $_GET['user_id'];
if (($_GET['activationkey']) == ($row_getUser['activationkey'])) {
$strQuery =	"UPDATE userTable SET status='activated' WHERE user_id='".$user_id."'";
mysql_query($strQuery) or die(mysql_error());
}
?>


Was This Post Helpful? 0
  • +
  • -

#8 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: how do you make a link that activates the user?

Posted 03 June 2009 - 11:25 PM

i saw it in your code, then use instate of $_SESSION $_GET
Was This Post Helpful? 1
  • +
  • -

#9 ninethousandfeet@msn.com  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 310
  • Joined: 09-February 09

Re: how do you make a link that activates the user?

Posted 03 June 2009 - 11:27 PM

i got it! thanks for both of your help. i had to remove the single quotes from the link that is mailed.

thank you!
Was This Post Helpful? 0
  • +
  • -

#10 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5234
  • View blog
  • Posts: 27,025
  • Joined: 10-May 07

Re: how do you make a link that activates the user?

Posted 03 June 2009 - 11:28 PM

Glad to see that you got it working! :D :^:
Was This Post Helpful? 0
  • +
  • -

#11 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: how do you make a link that activates the user?

Posted 03 June 2009 - 11:31 PM

very nice!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1