Hi, you know I'm doing a login and I do not know how to restrict access via url but I read some php sessions and I'm trying but I'm a bit lost and I have something like my login page that calls through an ajax request an intermediate file called call_login and this returns a value of true or false, I use it only to see if everything was correct and that call_login passes my username and password to read.php, which in this return is true or false, depending on whether I found that user or not. I know that I have to capture the user with whom I log in and that I do in the login after I return all good to read and that and I do so:
<script> $('#log').on('click',function(e){
e.preventDefault();
var user = $("#user-login").val();
var parametros = {
'user' : user,
'pass' : $("#pass-login").val(),
}
$.ajax({
data: parametros,
url: 'php/php-pdo/call_login.php',
type: 'post',
dataType: 'json',
success:function(d){
console.log(d);
if (d == true) {
console.log("Acceso concedido");
// console.log(user);
<?php $_SESSION['username'] = $user; ?> //Si se loguea correctamente creamos sesion con nombre de el usuario
window.location.href = "index.php";
} else {
console.log("Acceso denegado");
}
},
error:function(e){
console.log(e);
}
})
})
</script>
my question is how I capture the name of my user who initiates the session, this line is what generates the error $ _SESSION ['username'] = $ user; and the other after that let me give error what else do? : Or I know I should start something like the session again on the page that I'm restricting with session_start () and then verify that it is not empty but I'm not sure hehe