So, this is a headscratcher. I am submitting a login form via ajax, which is working properly. On login I am setting several $_SESSION variables and loading 3 php files into divs to refresh the data using the user's account info. Here is the javascript:
function processLogin() {
$.post("/login/index.php" , $("#djloginform").serialize(),
function(data) {
if (data.error == 0) {
$("#featuredJobs").load("/jobs/featured.php");
$("#allJobs").load("/jobs/alljobs.php");
$("#loginbox").load("/login/loggedin-yes.php");
}
else {
alert(data.error);
$("#djloginemail").val("").focus();
$("#djloginpassword").val("");
}
}, 'json');
}
featured.php and alljobs.php is loading correctly and using the $_SESSION variables, so they are being set correctly and used by 2 out of the 3 php files. Here is the code for what isn't showing:
Logged in as
<span style="font-weight: bold;">
<?php echo $_SESSION['djfullname']; ?>
</span>
I just get "Logged in as", but when I refresh the page I get "Logged in as [name]".
The three pages are all using the same exact $_SESSION variables, so I don't know what's going on here. Any ideas?
use session_start(); before echoing $_SESSION['djfullname'].