PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old October 23rd, 2009, 10:39 AM
Peuplarchie's Avatar
Peuplarchie Peuplarchie is offline
Stand
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Québec
Posts: 208 Peuplarchie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 11 h 52 m 43 sec
Reputation Power: 3
Post Match code in link with code with one in file and extract line

Good day you all,
I work on a email confirmation system, I'm stuck on the part of matching the code in the confirmation link with the one in the file so I can find which line to move from the pending file to the confirmed file.

the lines in the file looks like that :

name, email, code
name, email, code

and the link look like :
http://mysite.com/confirmed.php?code=123456

How can I look for the line in the file that match the code in the link

Thanks!
__________________
That's why we are not alone on earth, to help each other !
Let's build !

Reply With Quote
  #2  
Old October 23rd, 2009, 01:41 PM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
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.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Match code in link with code with one in file and extract line


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek