Re: RES: [PHP] Re: problem with my login script

2012-10-02 Thread ma...@behnke.biz
Just for the record, I'll sign that one.
There is a reason for continue, break and return to exist.

Just make sure, that your code is understandable and there is no problem using
these exits.

If your code is that complicated, that you don't understand a break in it, the
problem is another.

Samuel Lopes Grigolato samuel.grigol...@gmail.com hat am 2. Oktober 2012 um
13:40 geschrieben:
 I follow this rule of thumb: small blocks of highly understandable code. If
 this demands ternary conditionals or breaks, so be it!

 -Mensagem original-
 De: Tim Streater [mailto:t...@clothears.org.uk]
 Enviada em: terça-feira, 2 de outubro de 2012 08:37
 Para: PHP General List
 Assunto: [PHP] Re: problem with my login script

 On 02 Oct 2012 at 12:07, Maciek Sokolewicz maciek.sokolew...@gmail.com
 wrote:

  On 02-10-2012 11:59, Bálint Horváth wrote:
  The problem was already solved. I forgot to send a copy to the list...
 
  Rodrigo, break!? Ohh man, it's a crazy idea... A developer DOES NOT
  use break at all (in a loop)... (switch is an exception)
 
  I personally find this statement to be utter bullshit. There is
  nothing wrong with using break. There is a very good reason why it's
  available in the language. In very many cases, it costs a lot less
  code to add a break than to add additional clauses to your
  while-conditional.

 Agree 100%.

 --
 Cheers  --  Tim


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

Marco Behnke
Dipl. Informatiker (FH), SAE Audio Engineer Diploma
Zend Certified Engineer PHP 5.3

Tel.: 0174 / 9722336
e-Mail: ma...@behnke.biz

Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal

http://www.behnke.biz

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: RES: [PHP] Re: problem with my login script

2012-10-02 Thread Thomas Conrad
My problem was solved no need to argue. I don't see why use a while
loop with a count variable when it produces the same result as a
foreach loop. As for using a break in the loop, I could add it but the
loop is gonna stop anyway as soon as it hits the end of the array. I
also didn't see the point in using the explode() function as long as I
remove the (in my opinion) useless index numbers from the text file
containing the username. The following code works as I expect it to:

?php
session_start();

$users = file(../inc/users.inc.php);

if(!empty($_POST['username'])  !empty($_POST['password'])){

if(filter_var($_POST['username'], 
FILTER_VALIDATE_EMAIL)){


foreach($users as $row){
$row = trim($row);
if($_POST['username'] == $row){
$_SESSION['logged_in'] = 1;
$_SESSION['username'] = $row;

}
}
if($_SESSION['logged_in'] != 1){
$error = 2;
}
}else{
$error = 4;
}
}else{
$error = 3;
}

if($error){
header(Location:);
}else{
header(Location:);
}


?

users.inc.php:

m...@email1.com
m...@email2.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php