Problem:
Whenever a user attempts to login, with the correct username and password, it redirects them to the fail.php page, which means that the login process failed. I can't figure out why! The connection and session is started on a different page. Does anyone have any suggestions? I'm guessing that the attempt to get the encrypted password is not working. I don't know though.
Code:
Code: Select all
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue):
mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
//Encrypt the password
if (isset($_POST['cpassword1'])) {$_POST['cpassword1'] = sha1($_POST['cpassword1']);}
// *** Validate request to login to this site.
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['cemail'])) {
$loginUsername=$_POST['cemail'];
$password=$_POST['cpassword1'];
$MM_fldUserAuthorization = "c_level";
$MM_redirectLoginSuccess = "success.php";
$MM_redirectLoginFailed = "fail.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_con_clients, $con_clients);
$LoginRS__query=sprintf("SELECT c_email, c_password1, c_level FROM c_register_info WHERE c_email=%s AND c_password1=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $con_clients) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = mysql_result($LoginRS,0,'c_level');
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
<div class="post">
<h2>Login Form</h2>
<form action="<?php echo $loginFormAction; ?>" method="POST" name="frmreg" id="frmreg"
onsubmit="MM_validateForm('cemail','','RisEmail','cpassword1','','R');return document.MM_returnValue">
<fieldset>
<legend>Login</legend>
<label for="cemail">Username: </label>
<input type="text" name="cemail" id="cemail" tabindex="1" size="30" />
<br />
<label for="cpassword1">Password:</label>
<input type="password" name="cpassword" id="cpassword" tabindex="2" size="15"/>
<br />
<label for="clogin" title="Click the Login button to complete the login process"> </label>
<input type="submit" name="submit" id="clogin" value="Login" tabindex="3" />
<input type="hidden" name="MM_insert" value="frmreg" />
</fieldset>
</form>
</div>