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
https://forums.phpfreaks.com/topic/75958-solved-validation-on-sign-up/
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.

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.-

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.