Page 1 of 1

Login problem.

Posted: Mon Apr 10, 2006 7:25 am
by miniature
I wrote this code:

Code: Select all

<?php
  echo "<center><div id=\"contentbox\">\n";
  echo "<h2><u>LOGIN</u></h2><br />\n";

  if($_POST['login']) {
    $login_counter = 0;

    $username = htmlspecialchars($_POST['username'], ENT_QUOTES);
    $password = htmlspecialchars($_POST['password'], ENT_QUOTES);
    $password_md5 = md5($password);
    $sql_login_activated = @mysql_query("SELECT * FROM digital_blog WHERE username='$username' AND password='$password_md5' AND activated=0") or die (mysql_error());
    $login_check_activated = @mysql_num_rows($sql_login_activated);

    echo "<center><div id=\"note\"><u>NOTES AFTER SENDING:</u><br /><br />\n";
    if($username == "") {
      $login_counter = 1;
      echo "<b>USERNAME REQUIRED</b><br />\n";
    }
    if($password == "") {
      $login_counter = 1;
      echo "<b>PASSWORD REQUIRED</b><br />\n";
    }
    if($login_check_activated > 0) {
      $login_counter = 1;
      echo "<b>BEFORE YOU LOGIN YOU NEED TO ACTIVATE</b><br />\n";
    }

    if($login_counter == 0) {
      $sql_login = @mysql_query("SELECT * FROM digital_blog WHERE username='$username' AND password='$password_md5' AND activated=1 AND login=0") or die (mysql_error());
      $login_check = @mysql_num_rows($sql_login);

      if($login_check > 0) {
        header("Location: index.php");
      }
      else {
        echo "<b>ERROR</b>\n";
      }
    }
    echo "</div></center><br />\n";
  }

  echo "<form method=\"post\" action=\"$PHP_SELF?d=login\">\n";
  echo "<b>USERNAME:</b><br /><input type=\"text\" name=\"username\" id=\"username\" /><br />\n";
  echo "<b>PASSWORD:</b><br /><input type=\"password\" name=\"password\" id=\"password\" /><br /><br />\n";
  echo "<input type=\"submit\" name=\"login\" id=\"login\" value=\" LOGIN \" /></form>\n";
  echo "</div></center>\n";
?>
And it's always printing "ERROR", even if the details true.

What can be the problem?
Thanks,
Yoav.

Posted: Mon Apr 10, 2006 9:05 am
by feyd
remove the @ operators from the code.

Posted: Mon Apr 10, 2006 10:14 am
by miniature
feyd wrote:remove the @ operators from the code.
It still doesn't work.

Posted: Mon Apr 10, 2006 10:43 am
by phpScott
did you get any errors or warning messages?
If so please post them.

Posted: Mon Apr 10, 2006 11:24 am
by miniature
phpScott wrote:did you get any errors or warning messages?
If so please post them.
No

Posted: Mon Apr 10, 2006 1:02 pm
by Christopher
You are always getting "ERROR" because the only way you can pass your first query is if "activated=0" and the only way your second query check passes is if "activated=1" so it can never succeed.

You should rewrite the whole thing with just one query. Fetch the row and check the actual values.

Posted: Mon Apr 10, 2006 2:11 pm
by LiveFree
And add

Code: Select all

error_reporting(0);
To the top of your script just to be sure

Posted: Mon Apr 10, 2006 2:20 pm
by feyd
E_ALL, not zero ;)

Run the following in a new file and tell us the results please.

Code: Select all

<?php

$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
$rg = (in_array(strtolower(ini_get('register_globals')), array(0, false, '', null, 'off')) ? 'Off' : 'On');
$de = (in_array(strtolower(ini_get('display_errors')), array(0, false, '', null, 'off')) ? 'Off' : 'On');
$so = (in_array(strtolower(ini_get('short_open_tag')), array(0, false, '', null, 'off')) ? 'Off' : 'On');
$eol = (isset($_SERVER['HTTP_HOST']) ? "<br />\n" : "\n");

$ec = array(
   'E_STRICT' => 2048,
   'E_ALL' => 2047,
   'E_USER_NOTICE' => 1024,
   'E_USER_WARNING' => 512,
   'E_USER_ERROR' => 256,
   'E_COMPILE_WARNING' => 128,
   'E_COMPILE_ERROR' => 64,
   'E_CORE_WARNING' => 32,
   'E_CORE_ERROR' => 16,
   'E_NOTICE' => 8,
   'E_PARSE' => 4,
   'E_WARNING' => 2,
   'E_ERROR' => 1,
);

$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
   if (($t & $v) == $v)
   {
      $e[] = $n;
      $t ^= $v;
   }
}
$er = $er . ' (' . implode(' | ', $e) . ')';

echo 'PHP Version: ' . $ve . $eol;
echo 'PHP OS: ' . $os . $eol;
echo 'Error Reporting: ' . $er . $eol;
echo 'Register Globals: ' . $rg . $eol;
echo 'Short Tags: ' . $so . $eol;
echo 'Display Errors: ' . $de . $eol;

?>

Posted: Mon Apr 10, 2006 4:10 pm
by miniature
feyd wrote:E_ALL, not zero ;)

Run the following in a new file and tell us the results please.

Code: Select all

<?php

$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
$rg = (in_array(strtolower(ini_get('register_globals')), array(0, false, '', null, 'off')) ? 'Off' : 'On');
$de = (in_array(strtolower(ini_get('display_errors')), array(0, false, '', null, 'off')) ? 'Off' : 'On');
$so = (in_array(strtolower(ini_get('short_open_tag')), array(0, false, '', null, 'off')) ? 'Off' : 'On');
$eol = (isset($_SERVER['HTTP_HOST']) ? "<br />\n" : "\n");

$ec = array(
   'E_STRICT' => 2048,
   'E_ALL' => 2047,
   'E_USER_NOTICE' => 1024,
   'E_USER_WARNING' => 512,
   'E_USER_ERROR' => 256,
   'E_COMPILE_WARNING' => 128,
   'E_COMPILE_ERROR' => 64,
   'E_CORE_WARNING' => 32,
   'E_CORE_ERROR' => 16,
   'E_NOTICE' => 8,
   'E_PARSE' => 4,
   'E_WARNING' => 2,
   'E_ERROR' => 1,
);

$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
   if (($t & $v) == $v)
   {
      $e[] = $n;
      $t ^= $v;
   }
}
$er = $er . ' (' . implode(' | ', $e) . ')';

echo 'PHP Version: ' . $ve . $eol;
echo 'PHP OS: ' . $os . $eol;
echo 'Error Reporting: ' . $er . $eol;
echo 'Register Globals: ' . $rg . $eol;
echo 'Short Tags: ' . $so . $eol;
echo 'Display Errors: ' . $de . $eol;

?>
http://royalgames.3dfaculty.com/a.php

Posted: Mon Apr 10, 2006 4:49 pm
by feyd
It would have been better to post the results like I asked. :?

Code: Select all

PHP Version: 4.3.11
PHP OS: Linux
Error Reporting: 2039 (E_USER_NOTICE | E_USER_WARNING | E_USER_ERROR | E_COMPILE_WARNING | E_COMPILE_ERROR | E_CORE_WARNING | E_CORE_ERROR | E_PARSE | E_WARNING | E_ERROR)
Register Globals: On
Short Tags: On
Display Errors: On

Posted: Mon Apr 10, 2006 5:13 pm
by miniature
feyd wrote:It would have been better to post the results like I asked. :?

Code: Select all

PHP Version: 4.3.11
PHP OS: Linux
Error Reporting: 2039 (E_USER_NOTICE | E_USER_WARNING | E_USER_ERROR | E_COMPILE_WARNING | E_COMPILE_ERROR | E_CORE_WARNING | E_CORE_ERROR | E_PARSE | E_WARNING | E_ERROR)
Register Globals: On
Short Tags: On
Display Errors: On
Why?

Posted: Mon Apr 10, 2006 5:42 pm
by LiveFree
He took the time to try to help you..

The absolute least you can do is post it so that he doesnt have to spend time going to the site

And you are trying a dumba$$ if you say "But it only takes 2 seconds to load"

Posted: Mon Apr 10, 2006 6:07 pm
by miniature
Tucker wrote:He took the time to try to help you..

The absolute least you can do is post it so that he doesnt have to spend time going to the site

And you are trying a dumba$$ if you say "But it only takes 2 seconds to load"

Code: Select all

PHP Version: 4.3.11
PHP OS: Linux
Error Reporting: 2039 (E_USER_NOTICE | E_USER_WARNING | E_USER_ERROR | E_COMPILE_WARNING | E_COMPILE_ERROR | E_CORE_WARNING | E_CORE_ERROR | E_PARSE | E_WARNING | E_ERROR)
Register Globals: On
Short Tags: On
Display Errors: On
And why he need so much time?

Posted: Tue Apr 11, 2006 10:02 pm
by miniature
Bump :)
I can now, right? It's 24 hours since my last post.