Hi, WebForums
I'm doing a login system, and it's working, but i'm having difficults in understand where does the "logout" go, other thing is that i want to improve the validation system - if someone could give me some tips.
Here are the codes i'm using
login form, "index.php":
<!----------JAVASCRIPT VALIDAR LOGIN---------------->
<script>
function validar() {
if (document.getElementById("username").value.length==0) {
alert("Introduza o seu Login");
document.getElementById("username").focus();
return false;
}
if (document.getElementById("pass").value.length==0) {
alert("Introduza a sua Password");
document.getElementById("pass").focus();
return false;
}
}
</script>
<!-------------------FORM LOGIN--------------------->
<td class = "table_title">
<h3> Log In </h3>
<form name="loginform" METHOD="POST" action="validapass.php" onsubmit="return validar()">
<table class=textologin align="center" cellspacing="0" cellpadding="0" width="25%">
<tr><td height="50"></td></tr>
<tr>
<td width="50">Username: </td>
<td width="150" align="left"><input name="username" size="15"></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td width="50">Password: </td>
<td width="150" align="left"><input type="password" name="pass" size="15"></td>
</tr>
<tr><td height="20"></td></tr>
<tr>
<td align="center"><input type="Submit" value="Log In"></td>
</tr>
</table>
</form>
</td>
username and password validation, "validapass.php":
<?php
session_start();
include "db_connect.php";
$username = $_POST['username'];
$pass = $_POST['pass'];
mysql_select_db($dbname, $connect);
$sql="SELECT username, password FROM alunos WHERE username='". $username. "'";
$resultado = mysql_query($sql, $connect) or die(mysql_error());
$num = mysql_fetch_assoc($resultado);
if ($username == $num['username'] AND $pass == $num['password']) {
header("Location: index_log.php");
} else {
header("Location: login_form.php");
}
mysql_close($con);
?>
If the login it's correct it opens "index_log.php":
In the end the "index_log" is the same as "index.php" the only diference is that appears "Login successful, user_name".
Can someone help me and give me some tips to improve the Login System?!
Thank you a lot,
PF2G