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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.