-1
I am creating a session in PHP and taking her ID with cookie via javascript, however I would like to know how I do to get other data besides the ID, as the name of the session for example.
index.html:
<!DOCTYPE html>
<html>
<head>
<title>teste</title>
</head>
<body>
<form action="login.php" method="POST">
Nome: <input type="text" name="nome"><br><br>
<input type="submit" value="Login">
</form>
</body>
</html>
login.php:
<?php
if(!isset($_SESSION))
{
session_start();
}
$_SESSION['usuario'] = $_POST['nome'];
$_SESSION['name'] = "Minha Sessao";
?>
<!DOCTYPE html>
<html>
<body>
Usuário Logado:<p id='teste'></p>
<script type="text/javascript">
var usuario = document.cookie;
alert(usuario);
document.getElementById('teste').innerHTML = usuario;
</script>
<a href="logout.php">Logout</a>
</body>
</html>
logout.php:
<?php
session_start();
if(isset($_SESSION['sessao']))
{
echo 'Não existe uma sessão para ser encerrada';
}else{
header("location:index.html");
}
?>
Session is something unique to the server. You cannot access the session via JS, you will need to do this by PHP, as you did using
$_SESSION
.– Woss