I've been trying to succesfully finish the Login part of my website to no avail. Everything works fine, and the user does get logged in right away, but the session is not maintained and I've ran out of ideas/help by googleing so I hope I can get a couple pointers here.
Here's a bit of the code I'm using:
<?php
if ( !isset($_SESSION["username"]) ){
if ( !isset($_POST["frm_enviarLogin"]) ){
?>
<div class="avisoForm"></div>
<form class="formLogin" id="form_Login" method="post" action="<?php echo $PHP_SELF;?>">
<input type="text" id="frm_username" name="frm_username" size="12" title="No mas de 12 caracteres"></input><label for="frm_username"> Username</label>
<input type="password" id="frm_password" name="frm_password" size="12" title="No mas de 12 caracteres"></input><label for="frm_password"> ContraseƱa</label>
<button type="submit" id="frm_enviarLogin" name="frm_enviarLogin">Entrar</button>
<?php
}
else
{
if ( ($_POST["frm_username"] == "admin") && ($_POST["frm_password"] == "pass") )
{
$_SESSION["username"] = "admin";?>
<p class="textoIngresar">Bienvenido, <?php echo $_SESSION["username"];?></p>
<?php
}
}
}
?>
Now, this code is placed in 'sidebar.php' and the thing is I have a 'header.php' on my website which is called with include (along with sidebar.php) from all of the diferent pages within the website. Where should I place session_start() for this to work? I've tried only adding it in 'header.php' but afaik it didn't work (the user gets logged in, but when moving to a different page the user is logged out now), and I've also tried placing session_start() everywhere, again with no results.
I'm pretty sure I'm doing some newbie mistake here but I just can't see it.
Thanks in advance,
etonB.