0
I made a small login screen using PHP session, but when I do the test to check if the session is already created the condition never "falls" in else
.
Code:
<?php
if(!isset($_SESSION))
{
session_start();
}else{
echo "<p>Sessao já existia</p>";
}
$_SESSION['usuario'] = $_POST['nome'];
$_SESSION['name'] = "Minha Sessao";
?>
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>
This is because the superglobal variable
$_SESSION
is never set until you call the functionsession_start
, function to initialize session variables.– Woss
But if I gave a session_start() before the check it wouldn’t just fall into Else ?
– Luiz Felipe da Silva
Luiz, do not make edits to the question that Sconfigure and invalidates the answers given. If the answers don’t meet your need means you didn’t ask what you wanted, then ideally create another question explaining the problem. The issues in the question are allowed when they aim to improve it, not change it.
– Woss