1
You are not receiving the false value, and displaying the Else block. It has been passed through the url and only executes the true value if block. Someone give me a help, I thank you. Follow the code below:
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<?php $logado = $_GET["logado"]; ?>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>IF Alternativo</title>
</head>
<body>
<?php if($logado) : ?>
</body>
</html> <h1>Bem vindo ao sistema!</h1>
<?php else : ?>
<h1>Faça o login</h1>
<form>
<input type="text" placeholder="Login" name="login"/>
<input type="password" placeholder="Senha" name="senha"/><br/>
<input type="submit" value="Entrar">
</form>
<?php endif; ?>
</body>
</html>
The log is a string, have you tried to compare $logged in === "true" ? Or how it is passing in the url, value 1/0/true/false?
– Rafael Withoeft
Not for $_GET, passing true or false, directly to the variable $logged in, sure, only I want to get for $_GET["logged in"] this value.
– Thiago
Okay, try to put it like this
$logado = (boolean) $_GET['logado'];
– Rafael Withoeft
I added (Boolean) and it didn’t work. Is there any other way to solve ? Using $_GET
– Thiago
both "true" and "false" are true when it comes to string. Try it the way @Rafaelwithoeft recommended:
if ($logado === 'true')
to make a literal comparison. Note that upper and lower case make a difference in this case.– Bacco
@Thiago, what value is coming in the $logged in variable? or better in the url? What value is passed in the url?
– Rafael Withoeft
The value is false, only it displays the content of if. Since it was to enter Else.
– Thiago
You tested if($logged in === 'true') ?
– Rafael Withoeft
@Thiago You can’t paste the URL here for us to see?
– Daniel Ribeiro
Tested here now, solved, Thank you very much @Rafaelwithoeft
– Thiago