tberger Posted March 19, 2007 Share Posted March 19, 2007 I want PHP to read data I have stored in a text file to pull out certain pieces of data. Right now when you log in - I want it to check my user text file to determine if the data is there. If so, I want the page to welcome the person - if not to let them know there is no match. Right now the page always returns no matches and I think it is in the function. I believe it is how the function is reading the file. I think if I explode the data in the text file, I might get it to work properly but i am not sure how. The current function is: <?php function getLogin($username, $password) { $email = trim($_POST['email']); $pass = trim($_POST['pass']); $file = "/staff/seebetra/homepage/ciss225/registered_users.txt"; $lines = file($file); $logged = FALSE; foreach($lines as $line) { if(preg_match("/^.+?:.+?:".preg_quote($email).":".preg_quote($pass)."$/s", trim($line))) { list($first, $last, $f_email, $f_pass) = explode(":", trim($line)); echo "Hello ".$first." ".$last."!"; $logged = TRUE; break; } } if(!$logged) echo "Sorry, you didn't match!"; } ?> Is there a way to explode on the text file instead to find the match? I appreciate any help I can get on this. Link to comment https://forums.phpfreaks.com/topic/43366-explode-function/ Share on other sites More sharing options...
boo_lolly Posted March 19, 2007 Share Posted March 19, 2007 i think you need to change this: function getLogin($username, $password) { $email = trim($_POST['email']); $pass = trim($_POST['pass']); to this: function getLogin($username, $password) { $username = trim($_POST['email']); $password = trim($_POST['pass']); Link to comment https://forums.phpfreaks.com/topic/43366-explode-function/#findComment-210610 Share on other sites More sharing options...
tberger Posted March 19, 2007 Author Share Posted March 19, 2007 Thanks - I did make that change but there was no difference. I think the problem is this line: if(preg_match("/^.+?:.+?:".preg_quote($username).":".preg_quote($password)."$/s", trim($line))) Can I do an explode here instead of the preg_match? Link to comment https://forums.phpfreaks.com/topic/43366-explode-function/#findComment-210620 Share on other sites More sharing options...
effigy Posted March 19, 2007 Share Posted March 19, 2007 Yes, see Example 2298, Example 2. Link to comment https://forums.phpfreaks.com/topic/43366-explode-function/#findComment-210628 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.