After reading for like 2 days a lot of Login Codes, i decided to make my own...
Here is the code:
<?
define('INCLUDE_CHECK',true);
require 'connect.php';
//Will include only if INCLUDE_CHECK is defined
session_name('gdLogin');
//Start gdLogin Session
session_set_cookie_params(2*7*24*60*60);
//Cookie for 2 weeks
session_start();
if($_SESSION['id'] && !isset($_COOKIE['gdCookie']) && !$_SESSION['rememberMe']){
/*If it's logged, but without cookie and not rememberMe checkbox*/
$_SESSION=array();
session_destroy();
//Session Destroyed
}
if(isset($_GET['logoff'])){
$_SESSION=array();
session_destroy();
header("Location:login.php");
exit;
}
if($_POST['submit']=='Login'){
//Chech Login Data
$err=array();
//This will take the errors in the login process
if(!$_POST['username'] || !$_POST['password']) { $err[]='Se deben llenar todas las casillas';}
//Any Empty fields
if(!coutn($err)){
$_POST['username']=mysql_real_escape_string($_POST['username']);
$_POST['password']=mysql_real_escape_string($_POST['password']);
$_POST['rememberMe']=(int)$_POST['rememberMe'];
//Escaping all input data
$row=mysql_fetch_assoc(mysql_query("Select id, usr FROM userinfo WHERE usr='{$_POST['username']}' AND pass='".md5($_POST['password'])."'"));
if($row['usr']){
//If everything is OK login
$_SESSION['usr']=$row['usr'];
$_SESSION['id'] =$row['id'];
$_SESSION['rememberMe']=$_POST['rememberMe'];
//Store some data in the session
}
else $err[]='Usuario con Contraseña equivocada';
}
if($err){ $_SESSION['msg']['login-err']=implode('<br />', $err);} //Save the error messages in the session
header("Location: login.php");
exit;
}
?>
<!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>Ingresar</title>
<style type="text/css">
.cabecera {color:#FFF; background-color:#407CBF; text-align:center}
</style>
<style type="text/css">
.textopque {font-size:12px; color:#407CBF}
</style>
</head>
<body>
<? if(!$_SESSION['id']): ?>
<table width="100%" height="60%">
<tr>
<td valign="middle">
<table height="10%">
<tr><td align="center">
<?
if($_SESSION['msg']['login-err']){
echo $_SESSION['msg']['login-err'];
unset($_SESSION['msg']['login-err']);
}
?>
</td></tr>
</table>
<tr>
<td valign="middle">
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="login" method="post" action="login.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3" class="cabecera"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="username" type="text"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="password" type="password"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td valign="middle"><input type="submit" name="Login" value="Login">
<span class="textopque">¿Recordar tus Datos?</span> <input type="checkbox" name="rememberMe" value"1"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</td>
</tr>
</table>
<? else: header("logged.php");
endif;
?>
</body>
</html>
The Connect.php file are my DB Connect Strings; so simple, but there's something wrong with that, i just don't know what it is.
BTW: I get this when i run it:
Notice: Undefined index: id in D:\xampp\htdocs\login\login.php on line 15
Notice: Undefined index: submit in D:\xampp\htdocs\login\login.php on line 31
Notice: Undefined index: id in D:\xampp\htdocs\login\login.php on line 86
Notice: Undefined index: msg in D:\xampp\htdocs\login\login.php on line 93
but the table shows up.
I think that's all. Any help would be really nice, 'cuz i need it working.!

PS: Sorry for my english, i'm from Venezuela...
PSS: This is currently working. If you want to see what else i've done with the code, go to my New Challenge: Remember Me Checbox
Edited by GerarD_91, 20 March 2011 - 03:35 PM.