Jump to content

Not Logging In


dean7

Recommended Posts

Hi all, on my website i have a login page to get to the members area, but there is somthing wrong in my script... It shows the login form, but every time i press login with the correct login detials it still says there wrong.

 

<title>Login</title><?
oB_start();
// allows to use cookies.
include("config.php");
if (!$logged[username])
{
if (!$_POST[login])
{
echo("
<center><form method=\"POST\">
<table>
<tr>
<td align=\"right\">
Username: <input type=\"text\" size=\"15\" maxlength=\"25\" name=\"username\">
</td>
</tr>
<tr>
<td align=\"right\">
Password: <input type=\"password\" size=\"15\" maxlength=\"25\" name=\"password\">
</td></tr><tr>
<td align=\"center\">
<input type=\"submit\" name=\"login\" value=\"Login\">
</td></tr><tr>
<td align=\"center\">
<a href=\"register.php\">Register Here</a>
</td></tr></table></form></center>");
}
if ($_POST[login]) {
// the form has been submitted.  We continue...
$username= $_POST['username'];
$password = md5($_POST['password']);
// the above lines set variables with the submitted information.  
$info = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error());
$data = mysql_fetch_array($info);
if($data[password] != $password) {
// the password was not the user's password!
echo "Incorrect username or password!";
}else{
$timestamp = time()+60; 
mysql_query("UPDATE users SET online='$timestamp' WHERE username='$username'");
// the password was right!
$query = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error());
$user = mysql_fetch_array($query);
// gets the user's information
setcookie("id", $user[id],time()+(60*60*24*5), "/", "");
setcookie("pass", $user[password],time()+(60*60*24*5), "/", "");
// the above lines set 2 cookies. 1 with the user's id and another with his/her password.  
echo ("<meta http-equiv=\"Refresh\" content=\"0; URL=http://*******.com/index2.php\"/>Thank You! You will be redirected");
}
}
}
else
{
// display the user controls.
$new = mysql_query("select * from pmessages where unread = 'unread' and touser = '$logged[username]'"); 
$new = mysql_num_rows($new);
echo ("<center>Welcome <b>$logged[username]</b><br /></center>
- <a href=\"editprofile.php\">Edit Profile</a><br />
- <a href=\"messages.php\">Private Messages ($new New)</a><br />
- <a href=\"members.php\">Member List</a><br />
- <a href=\"logout.php\">Logout</a>
- <a href=\"admin.php\">Admin panel</a>");

}
?>

 

Thanks for you help.

Link to comment
https://forums.phpfreaks.com/topic/179810-not-logging-in/
Share on other sites

try this

 

<title>Login</title><?
oB_start();
// allows to use cookies.
include("config.php");
if (!$logged[username])
{
if (!$_POST[login])
{
echo("
<center><form method=\"POST\">
<table>
<tr>
<td align=\"right\">
Username: <input type=\"text\" size=\"15\" maxlength=\"25\" name=\"username\">
</td>
</tr>
<tr>
<td align=\"right\">
Password: <input type=\"password\" size=\"15\" maxlength=\"25\" name=\"password\">
</td></tr><tr>
<td align=\"center\">
<input type=\"submit\" name=\"login\" value=\"Login\">
</td></tr><tr>
<td align=\"center\">
<a href=\"register.php\">Register Here</a>
</td></tr></table></form></center>");
}
if ($_POST[login]) {
// the form has been submitted.  We continue...
$username= $_POST['username'];
$password = md5($_POST['password']);
// the above lines set variables with the submitted information.  
$info = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error());
$data = mysql_fetch_array($info);
if($data['password'] != $password) {
// the password was not the user's password!
echo "Incorrect username or password!";
}else{
$timestamp = time()+60; 
mysql_query("UPDATE users SET online='$timestamp' WHERE username='$username'");
// the password was right!
$query = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error());
$user = mysql_fetch_array($query);
// gets the user's information
setcookie("id", $user[id],time()+(60*60*24*5), "/", "");
setcookie("pass", $user[password],time()+(60*60*24*5), "/", "");
// the above lines set 2 cookies. 1 with the user's id and another with his/her password.  
echo ("<meta http-equiv=\"Refresh\" content=\"0; URL=http://*******.com/index2.php\"/>Thank You! You will be redirected");
}
}
}
else
{
// display the user controls.
$new = mysql_query("select * from pmessages where unread = 'unread' and touser = '$logged[username]'"); 
$new = mysql_num_rows($new);
echo ("<center>Welcome <b>$logged[username]</b><br /></center>
- <a href=\"editprofile.php\">Edit Profile</a><br />
- <a href=\"messages.php\">Private Messages ($new New)</a><br />
- <a href=\"members.php\">Member List</a><br />
- <a href=\"logout.php\">Logout</a>
- <a href=\"admin.php\">Admin panel</a>");

}
?>

 

this was the problem:

 

You put:

 <?php 
if($data[password] != $password) {
?>

 

this is the fix:

<?php
if($data['password'] != $password) {
?>

 

-John

Link to comment
https://forums.phpfreaks.com/topic/179810-not-logging-in/#findComment-948652
Share on other sites

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.