Jump to content

Recommended Posts

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!

 

 

Something like this should work...

 

if(isset($_GET['code'])) {
   $row = find_row($_GET['code']);
   print_r($row);
}

function find_row($code) {
   $file = fopen('test.txt', 'r');
   while($row = fgets($file)) {
      $columns = explode(', ', $row);
      if(trim($columns[2]) == $code) {
         fclose($file);
         return $columns;
      }
   }
   return FALSE;
}

Something more like...

 

if(isset($_GET['code'])) {
   $row = move_line($_GET['code']);
   print_r($row);
}

function move_line($code) {
   $lines = file('old.txt');
   $found_line = "";

   foreach($lines as $k=>$line) {
      $columns = explode(', ', $line);	
      if(trim($columns[2]) == $code) {
         $found_line = $line;
         unset($lines[$k]);
         break;
      }
   }

   if(!empty($found_line)) {
      $f = fopen('old.txt', 'w+');
      foreach($lines as $k=>$line) {
         fwrite($f, $line);
      }
      fclose($f);

      $f = fopen('new.txt', 'a');
      fwrite($f, $line);
      fclose($f);
   }
}

You will need to debug it then. You should have all the relevant code there to achieve your task. You will just have to use a combination of echo and print_r at differn't positions to find out what values are being read where and see what it doesn't change the files.

It working now but it don't move the right line

 


<?PHP
if(isset($_GET['code'] , $_GET['user'])) {
   $row = move_line($_GET['code'], $_GET['user']) ;
   print_r($row);
}

function move_line($code, $user) {
   $lines = file('savedinfo.txt');
   $found_line = "";




   foreach($lines as $k=>$line) {
      $columns = explode(', ', $line);




      if(trim($columns[3]) == $code && trim($columns[0]) == $user ){
         $found_line = $line;
         unset($lines[$k]);
         break;
      }
   }




   if(!empty($found_line)) {
      $f = fopen('savedinfo.txt', 'w+');
      foreach($lines as $k=>$line) {
         fwrite($f, $line);
      }
      fclose($f);






      $f = fopen('SecWall/Passwords/members.txt', 'a');
      fwrite($f, $line);
      fclose($f);
   }
}

?>

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.