Help With Login Script?
Posted: Tue Apr 10, 2007 1:22 pm
Hello everyone,
I have a login system/class but I am having problems with my login part. I have a registration and I added users and when I login it says that the usernames and passwords are wrong when I am 100% sure that they are right.
Here is the login script.
and here is the php code that handles the errors
Messages.php:
Thanks For Your Time
This is kinda urgent
I have a login system/class but I am having problems with my login part. I have a registration and I added users and when I login it says that the usernames and passwords are wrong when I am 100% sure that they are right.
Here is the login script.
Code: Select all
login.php:
<?
session_start();
if(isset($_GET['reg'])){
$reg=$_GET['reg'];
}else{
$reg="";
}
if($reg==1){
$msg1="<font color=\"#FF0000\"><b>Your details have been added, please login</b></font>";
}elseif($reg==2){
$msg1="<font color=\"#FF0000\"><b>You have been successfully logged out.</b></font>";
}
if(isset($_POST['submit'])){
if( empty($_POST['uname']) && (empty($_POST['upass']))){
header( "Location:Messages.php?msg=1" );
exit();
}
//transfer to shorter var
$n=$_POST['uname'];
$p=$_POST['upass'];
//connect to db
include('config.php');
$query="select * from user where uname='$n' and pw='$p' ";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if($num>0 ){
//put in session vars
$mytime=time();
$mytime=date("H:i:s A",$mytime);
$_SESSION['time'] = $mytime;
$_SESSION['status'] = 'logged';
$_SESSION['username'] = $n;
//goto next page
header("location:welcome.php");
exit;
}else{
$_SESSION['status'] = 'not logged';
header( "Location:Messages.php?msg=2" );
exit();
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/Auth.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Login</title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<link href="styleLog.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellspacing="7" cellpadding="0">
<tr class="temptitle">
<td><!-- InstanceBeginEditable name="EditRegion4" -->Login<!-- InstanceEndEditable --></td>
</tr>
<tr>
<td><!-- InstanceBeginEditable name="EditRegion3" -->
<form name="form1" method="post" action="login.php">
<table width="81%" border="0" align="center" cellpadding="0" cellspacing="3">
<tr class="listtop">
<td colspan="3">Login Status:<? if(isset($msg1)){
echo "$msg1";
}?></td>
</tr>
<tr>
<td width="9%">Username</td>
<td width="41%"><input name="uname" type="text" id="uname" size="50"></td>
</tr>
<tr>
<td>Password</td>
<td><input name="upass" type="text" id="upass" size="50"></td>
</tr>
<tr>
<td colspan="2"><div align="center"><a href="password.php">Forgotten your password?</a>|<a href="register.php">Register</a> </div></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="Login"></td>
</tr>
</table>
</form>
<!-- InstanceEndEditable --></td>
</tr>
<tr>
<td><div align="center">Copyright 2005 </div></td>
</tr>
</table>
</body>
<!-- InstanceEnd --></html>and here is the php code that handles the errors
Messages.php:
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/Auth.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Messages</title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<link href="styleLog.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellspacing="7" cellpadding="0">
<tr class="temptitle">
<td><!-- InstanceBeginEditable name="EditRegion4" -->Message<!-- InstanceEndEditable --></td>
</tr>
<tr>
<td><!-- InstanceBeginEditable name="EditRegion3" --><?php
$msg=$_GET['msg'];
switch($msg){
case 1:
echo "Please enter your username and password.";
break;
case 2:
echo "Your username and password do not match, please try again.";
break;
case 3:
echo "Please enter your username and password";
break;
case 4:
echo "Please enter your password";
break;
case 5:
echo "Your confirmation password has been mistyped or is empty,please try again";
break;
case 6:
echo "The username you have choosen is already taken, Please choose a new one";
break;
case 7:
echo "Please fill in ALL the fields";
break;
case 8:
echo "Your username is either spelled incorrect or does not exist, please try again";
break;
case 9:
$em=$_GET['email'];
echo "Your password has been sent to <b>$em</b>" ;
break;
case 10:
echo "There was a error while trying to send the message, please check your mail settings.";
break;
}
?> <!-- InstanceEndEditable --></td>
</tr>
<tr>
<td><div align="center">Copyright 2005 </div></td>
</tr>
</table>
</body>
<!-- InstanceEnd --></html>Thanks For Your Time
This is kinda urgent