Hi,
Please, I have some code for a login page i have except it doesn’t seem to be working and by this i mean when i enter a correct username and password and click log in, the form just reloads and stays on the same login page. If anyone could suggest some possible solution that would be great, im quite new to PHP and haven’t had any luck with fixing this so far. Here is my code :
<?php require_once('../Connections/conexao.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$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;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['login'])) {
$loginUsername=$_POST['login'];
$password=$_POST['senha'];
$MM_fldUserAuthorization = "id_nivel";
$MM_redirectLoginSuccess = "base.php";
$MM_redirectLoginFailed = "index.php";
$MM_redirecttoReferrer = false;
mysql_select_db($tabela, $con);
$LoginRS__query=sprintf("SELECT id_usuario, login, senha, id_nivel FROM usuarios WHERE login=%s AND senha=password('$password') AND activo = 1",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $con) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = mysql_result($LoginRS,0,'id_nivel');
$loginStrId = mysql_result($LoginRS,0,'id_usuario');
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
$_SESSION['MM_UserId'] = $loginStrId;
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Locbat - Website Management</title>
<link rel="shortcut icon" href="../imagens/empresas/locbat_icon.ico">
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<script type="text/javascript">
function setfocus(){
document.getElementById('login').focus();
};
</script>
<body onload="setfocus();">
<div id="box">
<div id="header">
<div id="header_logo">
</div><!--header logo-->
</div>
<div id="painel_de_login">
<div class="alert">
</div>
<form method="POST" action="<?php echo $loginFormAction; ?>" name="login_erro">
<fieldset>
<legend>Efectue a autenticação</legend>
<label>
<span>Utilizador</span>
<input type="text" name="login" id="login" />
</label>
<label>
<span>Password</span>
<input type="password" name="senha" id="senha" />
</label>
<input type="submit" name="logar" value="entrare" class="login_btn"/>
</fieldset>
</form>
<span style="color:#FFF; text-align:right" ><a href="forgot_password.php">Esqueci a senha!</a></span>
</div><!-- Painel de login-->
</div>
</body>
</html>