Greetings, I have a basic log system, but I want you to show who is logged in, here is my code:
<?php
/* start the session */
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Check Login</title>
<meta charset = "utf8" />
</head>
<body>
<?php
$host_db = "localhost";
$user_db = "root";
$pass_db = "****";
$db_name = "****";
$tbl_name = "usuarios";
// Connect to server and select databse.
mysql_connect("$host_db", "$user_db", "$pass_db")or die("Cannot Connect to Data Base.");
mysql_select_db("$db_name")or die("Cannot Select Data Base");
// data enviada desde el formulario
$username = $_POST['username'];
$password = $_POST['password'];
$sql= "SELECT*FROM $tbl_name WHERE usuario='$username' and password='$password'";
$result=mysql_query($sql);
// counting table row
$count = mysql_num_rows($result);
// If result matched $username and $password
if($count == 1){
$_SESSION['loggedin'] = true;
$_SESSION['username'] = $username;
$_SESSION['start'] = time();
$_SESSION['expire'] = $_SESSION['start'] + (30 * 60) ;
header('location: inicio.php');
}
else {
echo "Usuario o contraseña estan incorrectos.";
echo "<a href='index.php'>Volver a Intentarlo</a>";
}
?>
</body>
</html>
And this is the page after the data is validated, this is where I want the name of the loqueado user to appear:
<?php
session_start();
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true) {
} else {
echo "Esta pagina es solo para usuarios registrados.<br>";
echo "<br><a href='index.php'>Login</a>";
exit;
}?>