Jump to content

[SOLVED] Having trouble logging in


Trium918

Recommended Posts

I cannot get the password() function to work.

 

 
<?
session_start();

if(!('username') && !('password'))
{
  // if the user has just tried to log in
  
  $username = stripslashes($_POST['username']);
  $password = stripslashes($_POST['password']);
  
  $db_conn = mysql_connect("localhost") or die(mysql_error());
  mysql_select_db("member_auth")or die(mysql_error());
  $query = "select * from user_info_auth "
           ."where username='$username' "
           ." and password=('password')";
  $result = mysql_query($query)or die(mysql_error());
  if (mysql_num_rows($result) >0 )
  {
    // if they are in the database register the user id
    $valid_user = $username;
    session_register("valid_user");
  }
}
?>
<html>
<body>
<h1>Home page</h1>
<? 

  if (session_is_registered("valid_user"))
  {
    echo "You are logged in as: $valid_user <br>";
    echo "<a href=\"logout.php\">Log out</a><br>";
  }
  else
  {
    if (isset($username))
    {
      // if they've tried and failed to log in
      echo "Could not log you in";
    }
    else 
    {
      // they have not tried to log in yet or have logged out
      echo "You are not logged in.<br>";
    }

    // provide form to log in 
    echo "<form method=post action=\"session.php\">";
    echo "<table>";
    echo "<tr><td>Userid:</td>";
    echo "<td><input type=text name=username></td></tr>";
    echo "<tr><td>Password:</td>";
    echo "<td><input type=password name=password></td></tr>";
    echo "<tr><td colspan=2 align=center>";
    echo "<input type=submit value=\"Log in\"></td></tr>";
    echo "</table></form>";
  }
?>
<br>
<a href="members_only.php">Members section</a>
</body>
</html>




Link to comment
https://forums.phpfreaks.com/topic/45979-solved-having-trouble-logging-in/
Share on other sites

I truely believe that this is some good code because

once it was working when register_global = On. Now

that it is off I am have trouble.

 

session_start();

if(!('username') && !('password'))
{
  // if the user has just tried to log in
  
  $username = stripslashes($_POST['username']);
  $password = stripslashes($_POST['password']);
  
  $db_conn = mysql_connect("localhost") or die(mysql_error());
  mysql_select_db("member_auth")or die(mysql_error());
  $query = "select * from user_info_auth "
           ."where username='$username' "
           ." and pass=password('password')";
  $result = mysql_query($query)or die(mysql_error());
  if (mysql_num_rows($result) >0 )
  {
    // if they are in the database register the user id
    $valid_user = $username;
    session_register("valid_user");
  }
}
?>
<html>
<body>
<h1>Home page</h1>
<? 

  if (session_is_registered("valid_user"))
  {
    echo "You are logged in as: $valid_user <br>";
    echo "<a href=\"logout.php\">Log out</a><br>";
  }
  else
  {
    if (isset($username))
    {
      // if they've tried and failed to log in
      echo "Could not log you in";
    }
    else 
    {
      // they have not tried to log in yet or have logged out
      echo "You are not logged in.<br>";
    }

    // provide form to log in 
    echo "<form method=post action=\"session.php\">";
    echo "<table>";
    echo "<tr><td>Userid:</td>";
    echo "<td><input type=text name=username></td></tr>";
    echo "<tr><td>Password:</td>";
    echo "<td><input type=password name=pass></td></tr>";
    echo "<tr><td colspan=2 align=center>";
    echo "<input type=submit value=\"Log in\"></td></tr>";
    echo "</table></form>";
  }
?>
<br>
<a href="logout.php">Members section</a>
</body>
</html>

I am having problems accessing variables

when register_global=Off

 

 

<?
session_start();

if ($_POST['username'] && $_POST['password'])
{
  // if the user has just tried to log in

  $db_conn = mysql_connect("localhost");
  mysql_select_db("member_auth");
  $query = "select * from use_info_auth "
           ."where name='$username' "
           ." and password=password('$password')";
  $result = mysql_query($query);
  if (mysql_num_rows($result) >0 )
  {
    // if they are in the database register the user id
    $valid_user = $username;
    session_register("valid_user");
  }
}
?>
<html>
<body>
<h1>Home page</h1>
<? 

  if (session_is_registered("valid_user"))
  {
    echo "You are logged in as: $valid_user <br>";
    echo "<a href=\"logout.php\">Log out</a><br>";
  }
  else
  {
    if (isset($username))
    {
      // if they've tried and failed to log in
      echo "Could not log you in";
    }
    else 
    {
      // they have not tried to log in yet or have logged out
      echo "You are not logged in.<br>";
    }

    // provide form to log in 
    echo "<form method=post action=\"session.php\">";
    echo "<table>";
    echo "<tr><td>Userid:</td>";
    echo "<td><input type=text name=username></td></tr>";
    echo "<tr><td>Password:</td>";
    echo "<td><input type=password name=password></td></tr>";
    echo "<tr><td colspan=2 align=center>";
    echo "<input type=submit value=\"Log in\"></td></tr>";
    echo "</table></form>";
  }
?>
<br>
<a href="members_only.php">Members section</a>
</body>
</html>

This is the original code. The thing is I cannot

get it working with register_global=Off

 

<?
session_start();

if ($userid && $password)
{
  // if the user has just tried to log in

  $db_conn = mysql_connect("localhost", "webauth", "webauth");
  mysql_select_db("auth", $db_conn);
  $query = "select * from auth "
           ."where name='$userid' "
           ." and pass=password('$password')";
  $result = mysql_query($query, $db_conn);
  if (mysql_num_rows($result) >0 )
  {
    // if they are in the database register the user id
    $valid_user = $userid;
    session_register("valid_user");
  }
}
?>
<html>
<body>
<h1>Home page</h1>
<? 

  if (session_is_registered("valid_user"))
  {
    echo "You are logged in as: $valid_user <br>";
    echo "<a href=\"logout.php\">Log out</a><br>";
  }
  else
  {
    if (isset($userid))
    {
      // if they've tried and failed to log in
      echo "Could not log you in";
    }
    else 
    {
      // they have not tried to log in yet or have logged out
      echo "You are not logged in.<br>";
    }

    // provide form to log in 
    echo "<form method=post action=\"authmain.php\">";
    echo "<table>";
    echo "<tr><td>Userid:</td>";
    echo "<td><input type=text name=userid></td></tr>";
    echo "<tr><td>Password:</td>";
    echo "<td><input type=password name=password></td></tr>";
    echo "<tr><td colspan=2 align=center>";
    echo "<input type=submit value=\"Log in\"></td></tr>";
    echo "</table></form>";
  }
?>
<br>
<a href="members_only.php">Members section</a>
</body>
</html>


Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.