Peuplarchie Posted October 23, 2009 Share Posted October 23, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/178744-match-code-in-link-with-code-with-one-in-file-and-extract-line/ Share on other sites More sharing options...
cags Posted October 23, 2009 Share Posted October 23, 2009 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; } Quote Link to comment https://forums.phpfreaks.com/topic/178744-match-code-in-link-with-code-with-one-in-file-and-extract-line/#findComment-942913 Share on other sites More sharing options...
Peuplarchie Posted October 23, 2009 Author Share Posted October 23, 2009 nice, and how can I extract the line and move it to another file ? Quote Link to comment https://forums.phpfreaks.com/topic/178744-match-code-in-link-with-code-with-one-in-file-and-extract-line/#findComment-942945 Share on other sites More sharing options...
cags Posted October 23, 2009 Share Posted October 23, 2009 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); } } Quote Link to comment https://forums.phpfreaks.com/topic/178744-match-code-in-link-with-code-with-one-in-file-and-extract-line/#findComment-942979 Share on other sites More sharing options...
Peuplarchie Posted October 23, 2009 Author Share Posted October 23, 2009 nice code, I had to change the possition of the code from 2 to 4. but it still don't work ? Quote Link to comment https://forums.phpfreaks.com/topic/178744-match-code-in-link-with-code-with-one-in-file-and-extract-line/#findComment-943146 Share on other sites More sharing options...
cags Posted October 23, 2009 Share Posted October 23, 2009 I didn't test it so theres quite likely a bug or two in there. What didn't work? Did it not remove it? Did it not insert it into the other file? Did it throw an error? Quote Link to comment https://forums.phpfreaks.com/topic/178744-match-code-in-link-with-code-with-one-in-file-and-extract-line/#findComment-943148 Share on other sites More sharing options...
Peuplarchie Posted October 23, 2009 Author Share Posted October 23, 2009 not remove and not insert, no error Quote Link to comment https://forums.phpfreaks.com/topic/178744-match-code-in-link-with-code-with-one-in-file-and-extract-line/#findComment-943151 Share on other sites More sharing options...
cags Posted October 23, 2009 Share Posted October 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/178744-match-code-in-link-with-code-with-one-in-file-and-extract-line/#findComment-943156 Share on other sites More sharing options...
Peuplarchie Posted October 24, 2009 Author Share Posted October 24, 2009 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); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/178744-match-code-in-link-with-code-with-one-in-file-and-extract-line/#findComment-943285 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.