0
Example in file code index php.:
<header>
<input type="checkbox" id="btn-menu">
<label for="btn-menu" class="icon-menu"></label>
<nav class="menu">
<ul>
<li><a href="index.php"><span class="icon-home"></span>Home</a></li>
<li><a href="#"><span class="icon-info"></span>Sobre</a></li>
<li><a href="#"><span class="icon-calendar"></span>Agendamento</a></li>
</ul>
</nav>
<button type="button" class="cadastro btn-login"><a href="login-cadastro.php">Login</a></button>
<button type="button" class="cadastro btn-cadastro"><a href="login-cadastro.php">Cadastre-se</a></button>
</header>
When the user logs in, he wants the Login and Register options to disappear, and instead of these options appear the name of who logged in.
I was thinking of replicating the code of index php. to the index-logated.php(example), and open a session in that new code by placing its name there.
Example in file code index-logated.php:
session_start();
<header>
<input type="checkbox" id="btn-menu">
<label for="btn-menu" class="icon-menu"></label>
<nav class="menu">
<ul>
<li><a href="index-logado.php"><span class="icon-home"></span>Home</a></li>
<li><a href="#"><span class="icon-info"></span>Sobre</a></li>
<li><a href="#"><span class="icon-calendar"></span>Agendamento</a></li>
</ul>
</nav>
echo "BEM-VINDO". $_SESSION['nome-usuario'];
</header>
I don’t know if this is the right way, it’s the only way I thought, and I know so far.
if I had a condition that would change directly in index.php would be the most practical solution in my view, but if it exists, I don’t have the knowledge of it yet.
ATTEMPT N°1:
<?php session_start();
require_once("Valida.php");
?>
<header>
<input type="checkbox" id="btn-menu">
<label for="btn-menu" class="icon-menu"></label>
<nav class="menu">
<ul>
<li><a href="index.php"><span class="icon-home"></span>Home</a></li>
<li><a href="#"><span class="icon-info"></span>Sobre</a></li>
<li><a href="#"><span class="icon-calendar"></span>Agendamento</a></li>
</ul>
</nav>
<?php
if ($v->getValida()) {
?>
<span><?php echo "Bem-vindo ".$_SESSION['email']; ?></span>
<?php}else{?>
<button type="button" class="cadastro btn-login"><a href="login-cadastro.php">Login</a></button>
<button type="button" class="cadastro btn-cadastro"><a href="login-cadastro.php">Cadastre-se</a></button>
<?php } ?>
</header>
File Valida.php
<?php
class Valida{
private $valida;
function getValida(){
return $this->valida;
}
function setValida($valida){
$this->valida = $valida;
}
}
?>
You can do it through if and Else to check that the $_SESSION['user-name'] is empty or set and then display the user name if the $_Session is true, you can do it all on the same page without the need for you to replicate the code
– UzumakiArtanis
Saul da Silva Rolim, the user has already been authenticated. ’ll take step by step 1° The user logs in.php 2° Authenticate in.php 3° Redirect from Authenticate.php to index.php if there is a condition that changes the index.php file to place the session, or if it is done the way I did above, and if you give to change the file, how it is done.
– Nicolas Guilherme Matheus
I understood what you meant Saul da Silva Rolim, was not seeing this possibility of condition next to html, Thank you.
– Nicolas Guilherme Matheus
you managed to make?
– UzumakiArtanis
not yet, but I know where the problem is, just trying to figure out how to fix it
– Nicolas Guilherme Matheus
I’m not able to do it yet, I edited the post, I put the files I’m trying. getValida() arrives in the validation file, displays, but in the header file it displays nothing. /// Something else, besides not reaching, my condition displays the 2, both the buttons and the welcome, if I reverse the condition it removes the 2(button is welcome)
– Nicolas Guilherme Matheus
A session will only cease to exist if you have destroyed it or it expires. Then just check if the session variable is set and display the information (assuming you stored the user name in the session)
– Adriano Luz
I solved the problem, my Else was next to the <?php}Else tag{?>
– Nicolas Guilherme Matheus