I've read a few questions already, and the answers don't seem to relate to my exact problem. My project is using the MVC pattern and Bootstrap. Index.php calls the invoke() function in Controller.php, which in turn includes my views depending on the actions.
My login button does the following:
case "login":
$name = $_POST['name']; $pass = $_POST['password'];;
$result = $this->model->loginUser($name,$pass);
if($result == 1){
session_start();
$_SESSION["username"]=$name;
$_SESSION["lang"]="";
include 'view/session.php';
}
else{
include 'view/login.php';
}
break;
It has access to the $_SESSION["username"] variable, which I use to say Welcome to.
Session and login PHP files consist in a bootstrap navbar. Logged in users have access to more options, like downloading files and viewing their profile. After trying to click on the profile or download buttons, that I've set the same way as the login one, with different values, obviously:
<form class="navbar-form" method="POST" action="index.php">
<button type="submit" class="btn btn-success" name="action" value="login"><?php echo LOGIN_TXT; ?></button>
</form>
In the Profile action, it does the following:
case "profile":
include 'view/session.php';
include 'view/profile.php';
break;
Not sure if this way is viable, but I've tried to implement it through "layers". Session and Login are the navbar layers, and the body is composed of the views like Profile or Download.
The issue here is that when the session view is called again, it ceases to have access to the variable, returning the following:
Welcome, Notice: Undefined variable: _SESSION in /(...)/mvc/view/session.php on line 44
What would possibly make the session die? I'm at a loss here.
How would I go on about using Javascript or even Ajax to make my sessions persistent? Is this even possible?