
October 23rd, 2009, 01:41 PM
|
|
Me
|
|
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937

Time spent in forums: 1 Week 5 Days 1 h 54 m 18 sec
Reputation Power: 4
|
|
open the file, loop through each line, explode each line by comma and compare the code. Be sure to also use trim() on each line to remove any newline characters on the end of the line.
PHP Code:
//get the code and user from $_GET
$code = $_GET['code'];
$user = $_GET['user'];
//load the user csv file
$file = file("users.txt");
//set the code to invalid
$codeValid = false;
//loop through the user file.
foreach($file as $line){
//explode each line to an array
$line = explode(",", $line);
//check if the user from $_GET matches the user in the file in a case insensitive manor
if(strcasecmp(trim($line[0]), $user)==0){
//check if the code from $_GET matches the code in the file in a case insensitive manor
if(strcasecmp(trim($line[2]), $code)==0){
//if code matches, set codeValid to true.
$codeValid = true;
}
//user found so exit the loop
break;
}
}
//check if the code was correct.
if($codeValid){
echo "Validation worked";
//from here you should do something like change the code
//in the customer's file to a keyword like "valid" or "true" to say it
//has been validated. Then when someone tries to login you
//can check if the code is "valid" or whatever you used to make
//sure they have done the validation email.
} else {
echo "Validation failed";
//here you would probably have a form so they can manually
//type in the code and user from the email just in case
//the link doesn't work.
}
I added that a username needs to be passed as well. If you don't pass the user, then if you have like 100 pending codes and a duplicate code is generated, it would just validate whatever the first code it would find instead of possibly the right user. You would just need to add the user to the link or you could even make it so when they visit the page they have to type the username into a field and click "validate" then validate the code based off of the form submitted values.
|