Jump to content

[SOLVED] Validation on Sign Up


oron

Recommended Posts

Hey all,

I was just wondering how exactly would I be able to create a validation for when someone signs up like, a email is sent and they have to click the link for their account to be activated. I have a rough Idea of what I would have to do... however I'm a bit unsure of how to get the random characters ect.

 

Thanks,

Nick

Link to comment
Share on other sites

one sec, i have a script I can show you, you will need to add 2 fields to your mysql database called Validate_key and validate  the key is a varchar(32) and the validate is a bool or int(1)

 

I found my script, so here is what you need

<?php

//generate a random string using your prefered method
$string = rand_string_gen($length);

//Id of the registered user
$id = mysql_insert_id();

//Table Name

$table = "";

//Table Primary Key

$p_key = "";

$q = "Update `".$table."` Set V_key = '".$string."' where '".$p_key."' = '".$id."'";

$r = mysql_query($q) or die(mysql_error());



//Add to your mailer body

$body .= "Please Verify your account by going to http://www.mysite.com/confirm.php?code='".$string."'&user='".$id."'";

?>

 

Then you will need to add a page similar to this that the link above goes to

<?php
<?php

$code = $_GET['code'];

$id = $_GET['id'];

if(!empty($code) && is_numeric($id)){

//table name

$table = "";

//Primary Key UserID

$p_key = "";

$id = mysql_real_escape_string($id);

$code = mysql_real_escape_string($code)
;
$q = Select count(*) from `".$table."` Where '".$p_key."' = '".$id."' and V_key = '".$code."'";

$r = mysql_query($q) or die(mysql_error());

if(mysql_result($r,0)>0)){

	$q ="Update `".$table."` Set V_set = '1' Where '".$p_key."' = '".$id."'";

	$r = mysql_query($q) or die(mysql_error());

	echo "Some message saying it worked";

}

else{

	echo "Some message saying code didn't match";

}

}

else{

echo "Invalid code";

}

?>

 

That will confirm the code is right, and basically on your login script add something saying if the validate = 0 dont' login. 

 

I will let you figure out the resend page.

Link to comment
Share on other sites

Just so you understand the concept.

 

A validation key would be just a randomly made alphanumeric key (letters and numbers) and this is stored in the database. You would send a simple e-mail with a link that looks like this:

 

http://www.yoursite.com/validate.php?id=######&key=13ufadjionhaf13490a

 

Then, on validate.php, grab the user id (parse it to make sure that it IS numeric, just in case someone tries to hack, etc...).

 

Use a query to grab the validation key from the database, match it to what the validation key is in the url... If they match, update validate to be 1 = true, 0 = false which is default.

 

Then, if they try to visit the page again, you could just check to see if they were already validated, etc...

 

-Give a man a fish, feed him for a day. Teach a man to fish, feed him for a lifetime.-

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.