Current location: Hot Scripts Forums » Programming Languages » PHP » Match code in link with code with one in file and extract line


Match code in link with code with one in file and extract line

Reply
  #1 (permalink)  
Old 10-23-09, 09:38 AM
peuplarchie's Avatar
peuplarchie peuplarchie is offline
Newbie Coder
 
Join Date: Nov 2008
Posts: 64
Thanks: 1
Thanked 0 Times in 0 Posts
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!
Reply With Quote
  #2 (permalink)  
Old 10-23-09, 10:13 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
PHP Code:

$lines file('flatfile.txt');

foreach (
$lines AS $line)
{
    list(
$name $email$code) = explode(','trim($line));

    if (
trim($code) == $_GET['code'])
    {
        
// Do something
        
        
break;
    }

Reply With Quote
  #3 (permalink)  
Old 10-23-09, 11:20 PM
peuplarchie's Avatar
peuplarchie peuplarchie is offline
Newbie Coder
 
Join Date: Nov 2008
Posts: 64
Thanks: 1
Thanked 0 Times in 0 Posts
nice code but how could I find which line that is so I can move it ?
Reply With Quote
  #4 (permalink)  
Old 10-24-09, 01:23 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Try this:
PHP Code:

<?php
if(!empty($_GET["code"]))
{
 
$fo fopen("pending.txt","r");
 while(!
feof($fo)){list($name[],$email[],$code[]) = explode(',',trim(fgets($fo)));}
 
fclose($fo);
 if(empty(
$name[count($name)-1]))
 {
  unset(
$name[count($name)-1]);
  unset(
$email[count($email)-1]);
  unset(
$code[count($code)-1]);
  }
 for(
$i=0;$i<count($code);$i++)
 {
  if(
$code[$i] == $_GET["code"])
  {
   
$tempName $name[$i];
   
$tempEmail $email[$i];
   
$tempCode $code[$i];
   unset(
$name[$i]);
   unset(
$email[$i]);
   unset(
$code[$i]);
   
$name array_merge($name);
   
$email array_merge($email);
   
$code array_merge($code);
   }
  }
 
$fo fopen("pending.txt","w");
 for(
$i=0;$i<count($name);$i++)
 {
  
$line $name[$i].",".$email[$i].",".$code[$i];
  
fwrite($fo,$line."\r\n");
  }
 
fclose($fo);
 if(
$tempName&&$tempEmail&&$tempCode)
 {
  if(
file_exists("confirmed.txt")){$fo fopen("confirmed.txt","a");}
  else{
$fo fopen("confirmed.txt","w");}
  
$line $tempName.",".$tempEmail.",".$tempCode;
  
fwrite($fo,$line."\r\n");
  
fclose($fo);
  }
 }
?>
__________________
Jerry Broughton
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
running code against contents of a file? vbsaltydog Perl 7 09-27-06 04:11 PM
PHP to extract info from a delimited text file 9999 PHP 8 07-17-06 03:08 AM
Extract Zip file in server dave111 Script Requests 3 12-10-05 11:34 PM


All times are GMT -5. The time now is 08:01 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.