0
Good evening, my question is very simple I would like to know how to display the username of the session on the console. I tried this way but only returns null.
<?php
session_start();
echo $_SESSION['usuario'] = 'Pedro';
?>
<!DOCTYPE html>
<html>
<head>
<title>teste</title>
</head>
<body>
<script type="text/javascript">
var teste = sessionStorage.getItem('usuario');
console.log(teste);
</script>
</body>
</html>
PHP session is one thing, JS sessionStorage is another completely different. One is on the server, one is on the client. In which of the two you stored the user name?
– Woss
i stored it on the server, but I wanted to take the session data by sessionStorage
– Pedro
Impossible. Research the concepts of client-side and server-side.
– Woss
So how would I recover the user name? Or there is no way ?
– Pedro
Through
$_SESSION['usuario']
, as you did in the beginning.– Woss