Place in php which user is connected

1

I would like to place the user who is currently logged in on the corner of my page, I do not know how it is done and for this I ask for your help, here I attach the index code that I am currently working on.

<?php
session_start();    

if (isset($_POST['aceptar'])) {

   require_once 'local.php';

   $usuario = mysqli_real_escape_string($conexion,$_POST['usuario']);
   $contrasena = mysqli_real_escape_string($conexion,$_POST['contrasena']);

   $sql = mysqli_query($conexion,"SELECT usuario FROM usuarios WHERE usuario='$usuario' AND contrasena='$contrasena' LIMIT 1");

   if(mysqli_num_rows($sql)===1) {

      $_SESSION['conectado']=true; 
      $_SESSION['usuario']=$usuario;
      $_SESSION['inicio'] = time();
      header ("location: /supercable/index.php");

   } else {
      echo 'Datos incorrectos.';
   }  

}
?>
<!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" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<meta content="IE=edge,requiresActiveX=true" http-equiv="X-UA-Compatible" />
<link rel="shortcut icon" href="imagenes/logo.ico" />
<link href="css1/Estilo.css" rel="stylesheet" type="text/css"/> 
<title>LOGIN</title>
<script>
    function login(){
        login.submit();
    }
</script>
</head>
<body style="background-image: url(imagenes/Fondo.jpg);">
<center>
<!-- tabla login --->
<form name="login" method="post" action="paginas/index.php">
<table width='350' border='0' class='ventanas' cellspacing='0' cellpadding='0'>
<tr>
    <td colspan='3' class='tabla_ventanas' height='10' colspan='3' align='center'>Ingresar al Sistema
</tr>
<tr><td colspan=3><br/></td></tr>
<tr>
<td colspan='3'>
    <center>
    <table>
    <tr>
        <td><strong>Usuario:</strong></td>
        <td><input type="text" name="Usuario" class="CajaTexto" size="30" x-webkit-speech="true"/></td>
    </tr>
    <tr>
        <td><strong>Contraseña:</strong></td>
        <td><input type="password" name="Password" class="CajaTexto" size="30" x-webkit-speech="true"/></td>
    </tr>
    </table>
    </center>
</td>
</tr>
<tr>
<td colspan=3 align='center'><img src='imagenes/HRline200.png' width='250'></td>
</tr>
<tr>
<td height='50' colspan=3 align='center'><button class="clean-gray" onclick="login();"> LOGIN </button></td>
</tr>
</table>
</form>
</center>
</body>
</html>
    
asked by Alsking 09.03.2017 в 01:24
source

1 answer

1

try this way.

<tr>
    <td><strong>Usuario: <?php echo $_SESSION['usuario']; ?></strong></td>
    <td><input type="text" name="Usuario" class="CajaTexto" size="30" x-webkit-speech="true"/></td>
</tr>

since you have the session_start() within the file the session remains active if you are going to show it in another file remember to declare at the beginning of the file session_start() so that the session does not end.

    
answered by 09.03.2017 в 02:29