I'm setting up a client site and I need to do login control. The user can log in normally and without error, but sending it to the main page when he is logged in is as if he had not logged on. Here's my code:
login.php
<form class="form-horizontal" action="conf/logar.php" method="POST">
<fieldset>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="user">Usuario</label>
<div class="col-md-2">
<input id="user" name="user" placeholder="login" class="form-control input-md" required="" type="text">
</div>
</div>
<!-- Password input-->
<div class="form-group">
<label class="col-md-4 control-label" for="senha">Senha</label>
<div class="col-md-2">
<input id="senha" name="senha" placeholder="senha" class="form-control input-md" required="" type="password">
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="log">Login</label>
<div class="col-md-4">
<button id="log" name="log" class="btn btn-success">Login</button>
</div>
</div>
</fieldset>
</form>
logar.php
include("conexao.php");
$user = $_POST["user"];
$senha = $_POST["senha"];
$userBusca = mysql_query("SELECT * FROM usuario WHERE usuario_login = '".$user.
"' AND usuario_senha = '".$senha.
"' ") or die(mysql_error("Erro ao fazer login"));
if (mysql_num_rows($userBusca) == 1) {
session_start(); //Inicia a sessão
$_SESSION["usuario_nome"] = $_POS["user"];
$_SESSION["usuario_senha"] = $_POST["senha"];
header("Location:../index_logado.php");
} else {
"<script>
alert('Usuário não encontrado! Informe os dados corretamente');
window.location.href = '../login.php'; < /script>";
}
I created a page that controls whether the user is logged in or not.
restrict.php
@session_start();
if(isset($_SESSION["usuario_nome"])){
}else{
header("Location:login.php");
}
But by adding 'restrict.php' to 'index_logged.php' it's as if the user has not logged in and I can not retrieve session data. Thanks for the help. Vlws!