Jump to content
Larry Ullman's Book Forums

Recommended Posts

I can't seem to get my activation link (code) to properly activate the link. I had a lot of trouble debugging it, but once I finished with that, the code runs through, and it keeps saying, "Your account could not be activated. Please re-check the link or contact the administrator." I can't tell what is failing though? Does my code look alright? I am almost sure that my database is correct.

 

Here is the main body of my code:

 

 

<?php

if (isset($_GET['x'], $_GET['y']) && filter_var($_GET['x'], FILTER_VALIDATE_EMAIL) && (strlen($_GET['y']) == 32 )) {

require (MYSQL);
$q = "UPDATE users SET active=NULL WHERE email=' " . mysqli_real_escape_string($dbc, $_GET['x']) . "' \n"
. "\n"
. "AND \n"
. " \n"
. "active=' " . mysqli_real_escape_string($dbc, $_GET['y']) . "' \n"
. "\n"
. "LIMIT 1";

$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));

if (mysqli_affected_rows($dbc) == 1) {
echo "<h3>Your account is now active; log in at any time.</h3>";

} else {
echo '<p class="error">Your account could not be activated. Please re-check the link or 
contact the administrator.</p>';
}

mysqli_close($dbc);

} else {

$url = BASE_URL . '/index.php';
ob_end_clean();
header("Location: $url");
exit();
}

?>

 

I know that my query is written very oddly. I wrote it like that because it kept feeding me errors and I just wanted it to work for now, so I fed it in very discretely.

 

Any help would be greatly appreciated.

Link to post
Share on other sites

Hi uncfelt1147,

 

I'm no expert in PHP, just like you I'm a newbie. I find your query statement a little bit long with all those \n's.

This is the code from Larry's book:

 

$q = "UPDATE users SET active=NULL WHERE (email='" . mysqli_real_escape_string($dbc, $_GET['x']) . "' AND active='" .mysqli_real_escape_string($dbc, $_GET['y']) . "') LIMIT 1";

 

I check always with phpMyAdmin that the person I'm activating is recorded in my database.

  • Upvote 3
Link to post
Share on other sites
  • 3 weeks later...
  • 4 months later...

Hi,

 

I copy-and-paste the activate.php

 

I indeed received emails with activation links for the first several days.

 

Now. It stops working. And I don't know why?

 

I learned from another post (http://www.larryullman.com/forums/index.php?/topic/1648-chapter-18-registerphp-sendmail/) to add sendmail_path =/usr/sbin/sendmail -t into my .ini file. It still didn't work.

 

I use:

 

Linux share host at godaddy.com

PHP version: 5.3.21

 

Can you help?

 

Eric P

Link to post
Share on other sites

spookie makes a good point. Make sure that the active column in the users table can actually be set to NULL, as that's not possible for columns by default. You may have to alter the active column in the users table to get things working properly.

 

Also, try echoing out your $q variable to the screen before you execute the query to make sure it's actually what it should be.

Lastly, try echoing out the value of mysqli_affected_rows($dbc) to see what it is (because clearly, it's not 1).

Link to post
Share on other sites

spookie makes a good point. Make sure that the active column in the users table can actually be set to NULL, as that's not possible for columns by default. You may have to alter the active column in the users table to get things working properly.

 

Also, try echoing out your $q variable to the screen before you execute the query to make sure it's actually what it should be.

Lastly, try echoing out the value of mysqli_affected_rows($dbc) to see what it is (because clearly, it's not 1).

 

I can see the root cause now. As I use godaddy.com hosting service, which requires the From email address MSUST be the hosted domain name. The email address does not necessarily need to exist, but there are SPAM filters on the outgoing emails to prevent SPAM and spoofing.

 

Eric P

Link to post
Share on other sites
  • 7 months later...

Another curious question about activation code is that I have seen some websites that enable the users to activate their new accounts by entering the random code received via cell phone numbers registered during the 'sign-up' process, which i think that it is quite fast, handy, and even secure (if I were wrong).

 

Have you got any book instructing this, Larry?

 

And do you guys know any resources about this to share?

 

Thanks,

Eric

Link to post
Share on other sites

I have not written that up, nor have I ever implemented it myself. There are services you can use to send text messages, however. I don't think of this route as fast, but it's certainly more and more common. Don't know any resources about it offhand. 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...