login.php
Código PHP:
<?
include("includes/connect.php");
include('languajes/english/register.php');
if ($_POST['username']) {
//Comprobacion del envio del nombre de usuario y password
$username=$_POST['username'];
$password=$_POST['password'];
if ($password==NULL) {
echo "La password no fue enviada";
}else{
$query = mysql_query("SELECT username,password FROM users WHERE username = '$username'") or die(mysql_error());
$data = mysql_fetch_array($query);
if($data['password'] != $password) {
echo "Wrong username/password";
}else{
$query = mysql_query("SELECT username,password FROM users WHERE username = '$username'") or die(mysql_error());
$row = mysql_fetch_array($query);
$_SESSION["s_username"] = $row['username'];
$_SESSION["s_lastlogin"] = $row['lastlogin'];
$sql = "INSERT INTO online (username, lastlogin) VALUES ('".$_SESSION["s_username"]."','".$_SESSION["s_lastlogin"]."')";
$result = mysql_query($sql);
}
}
}
?>
<!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=iso-8859-1" />
<title>Untitled Document</title>
<link href="styles/crystal.css" rel="stylesheet" type="text/css" />
</head>
<?php
if (isset($_SESSION['s_username'])) {
echo ('
<body class="body">
<div class="div_container">
<div class="div_title">Log In</div>
');
echo ('<div class="div_text">Welcome
');
echo ucfirst($_SESSION['s_username']);
echo ('
<br />
<a href="logout.php">Logout</a>
</div>
</div>
<br />
</body>
');
}
else
{
echo('
<body class="body">
<form method="POST">
<div class="div_container">
<div class="div_title">Log In</div>
<div class="div_text">
Username:
<br />
<input name="username" type="text" />
<br />
<br />
Password:
<br />
<input name="password" type="password" />
<br />
<br />
<input type="submit" name="Submit" value="'
);
echo $lang_register["Submit"];
echo('
" />
</div>
<div class="div_text">
<a href="register.php">Register</a>
</div>
</form>
</body>
');
exit;
}
?>
</html>
Código PHP:
<?php
session_start();
include("includes/connect.php");
$lastlogin=date("d/m/Y h:i");
$username=($_SESSION['s_username']);
$query = "DELETE FROM online WHERE username = ".$username;
mysql_query($query);
session_destroy();
exit;
?>
La cosa es que al realizar el logout no se borra el usuario y no entiendo porque :S ya que la session no se cerro, sigue avierta y deberia capturar el nombre de usuario de la sesion actual.