You are here: Breaking out of a foreach/function « PHP Language « IT news, forums, messages
Breaking out of a foreach/function

Posted by Laiverd.COM on 03/22/07 21:54

Hi,

I'm working on this (assumed very simple) function that reads data from a
textfile and then performs a check for a valid login. Problem is that - as I
see it - the function should immediately return true if a valid login is
found, but it doesn't. This has been staring me in the face for the second
evening nou, and I don't see it.
It seems like the foreach loop is never stopped, and goes all the way
thorugh, while it shouldn't. Forgive me if I'm simply missing the obvious ;)
I also tried to end the loop with a break, and tried a non-strict
comparison. Both to no avail.

Of course I'm open to any way this function can be improved, but am most of
all curious as to why it wouldn't work now.


This is the function:
function isValidLogin()
{
global $passFile;
// get lines of file into array
$fp = file($passFile);
// loop through the array
// print_r($fp);
foreach($fp as $line){
// turn each array element into an array of its own
$words = explode(",",$line);
//print_r($words)."<br />";
if($words[0]==$_POST['loginname']){
if (($words[1]==$_POST['password'])){
echo "<br />login correct";
return true;
}
}
}
echo "login incorrect";
return false;
}

Thanks for any input,
John

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация