Login problem.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
miniature
Forum Newbie
Posts: 14
Joined: Sun Apr 09, 2006 3:41 pm

Login problem.

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

remove the @ operators from the code.
miniature
Forum Newbie
Posts: 14
Joined: Sun Apr 09, 2006 3:41 pm

Post by miniature »

feyd wrote:remove the @ operators from the code.
It still doesn't work.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

did you get any errors or warning messages?
If so please post them.
miniature
Forum Newbie
Posts: 14
Joined: Sun Apr 09, 2006 3:41 pm

Post by miniature »

phpScott wrote:did you get any errors or warning messages?
If so please post them.
No
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
(#10850)
LiveFree
Forum Contributor
Posts: 258
Joined: Tue Dec 06, 2005 5:34 pm
Location: W-Town

Post by LiveFree »

And add

Code: Select all

error_reporting(0);
To the top of your script just to be sure
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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;

?>
miniature
Forum Newbie
Posts: 14
Joined: Sun Apr 09, 2006 3:41 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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
miniature
Forum Newbie
Posts: 14
Joined: Sun Apr 09, 2006 3:41 pm

Post 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?
LiveFree
Forum Contributor
Posts: 258
Joined: Tue Dec 06, 2005 5:34 pm
Location: W-Town

Post 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"
miniature
Forum Newbie
Posts: 14
Joined: Sun Apr 09, 2006 3:41 pm

Post 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?
miniature
Forum Newbie
Posts: 14
Joined: Sun Apr 09, 2006 3:41 pm

Post by miniature »

Bump :)
I can now, right? It's 24 hours since my last post.
Post Reply