Re: problem with my login script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"As a Oo developer, a run away from using switch" - I don't understand
this: OOP and switch could be good together and I also prefer switch eg. at
action or page selection...

break is an old stuff and not a nice solution (like "goto")... killing a
procedure!? -means wrong planning of an app! (and jumping in the code with
goto also like this)


On Tue, Oct 2, 2012 at 12:11 PM, Rodrigo Silva dos Santos <
rodrigos.santos01@xxxxxxxxx> wrote:

> Better solution than mine (that don't even make a code)
>
> As a Oo developer, a run away from using switch, so I should never use
> break too... Good to know. By the way, what's the problem with it?
>
>
> Enviado por Samsung Mobile
>
>
>
> Bálint Horváth <hbalint@xxxxxxxxx> escreveu:
>
>
>
> 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)
>
> In the other hand Thomas, you should use while and count the lines and u
> need to test if username found...
>
> Yeah, this script is near to the good solution:
> <?php
>
> session_start();
>
> $users = file("users.inc.php");
>
> if (!empty($_POST['username']) && !empty($_POST['password'])) {
>     if (filter_var($_POST['username'], FILTER_VALIDATE_EMAIL)) {
>         $ui = 0;
>         while ($ui < count($users) && $error != "0") {
>             $user = explode(' ', trim($users[$ui]));
>             if ($_POST['username'] == $user[1]) {
>                 $_SESSION['logged_in'] = 1;
>                 $_SESSION['username'] = $user[1];
>                 $error = "0";
>             } else{
>                 $error = "2";
>             }
>             $ui++;
>         }
>     } else {
>         $error = "4";
>     }
> } else {
>     $error = "3";
> }
>
> if ($error == "0") {
>     print("redirecting");
> } else {
>     print("error: " . $error);
> }
>
> ?>
>
> On Tue, Oct 2, 2012 at 8:52 AM, Thomas Conrad <koopasforever@xxxxxxxxx
> >wrote:
>
> > I'm currently learning php and as a challenge, I'm creating a login
> > script using text files to store the information (until I learn how to
> > handle databases with php).
> > The problem I'm having is the if statement in my while loop is only
> > evaluated on the last iteration of the while loop, so its only
> > comparing the last username in the file and no others.
> >
> > Heres the code:
> >
> > <?php
> >         session_start();
> >
> >         $users = file("../inc/users.inc.php");
> >
> >                 if($_POST['username'] && $_POST['password']){
> >
> >                         if(ereg("^[^@ ]+@[^@ ]+\.[^@ \.]+$",
> > $_POST['username'])){
> >
> >
> >                                 while(list($id ,$username) =
> each($users)){
> >                                         if($_POST['username'] ==
> > $username){
> >                                                 $_SESSION['logged_in'] =
> 1;
> >                                                 $_SESSION['username'] =
> > $username;
> >
> >                                         }
> >                                 }
> >                                 if($_SESSION['logged_in'] != 1){
> >                                         $error = "2";
> >                                 }
> >                         }else{
> >                                 $error = "4";
> >                         }
> >                 }else{
> >                         $error = "3";
> >                 }
> >
> >         if($error){
> >                 header("Location:
> > http://koopasforever.com/scripts/login.php?error=$error";);
> >         }else{
> >                 header("Location: http://koopasforever.com/";);
> >         }
> >
> >
> > ?>
> >
> > I have checked all my variables and they all contain the proper
> information
> >
> > Some help would be greatly appriciated, Thanks
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux