WHy don't you set the session variable within the login function/include?
diafol
Rhod Gilbert Fan (ardav)
7,796 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
This sounds a bit overcomplicated. Why not have the js refresh the area of the screen? You can pass an array of data from the php include (as an array - json is great for this) back to the js. JS then updates the relevant areas.
diafol
Rhod Gilbert Fan (ardav)
7,796 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
No, it's as I thought.
If your loggedin.php file is enclosed within say a div tag with an 'id' set to 'log', you can set the contents of the div to anything you want with js after it receives the data from the php script.
<div id="log">
<?php include('includes/loggedin.php');?>
</div>
<...some other stuff to cause ajax call to a js script login(), e.g. form button...>
The js then can do something like this (I'm using jQuery here - useful for Ajax):
function login(){
var user = $('#username').val();
var pw = $('#pw').val();
$.post("includes/login.php", { "user": user, "pw": pw },
function(data){
if(data.resultvalue == "success"){
$("#login").html(data.emailaddr);
}else{
$("login").html("<p>Your login details are incorrect!</p>");
}
},
"json");
}
This example is a little raw, but I expect you get the idea.
The login.php can include the loggedin.php file and return the contents as emailaddr if the login details are valid. I use json when I want to return an array of data. It's simple and tends to 'just work'.
diafol
Rhod Gilbert Fan (ardav)
7,796 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
SORRY
$("#login").html(data.emailaddr);
}else{
$("login").html("<p>Your login details are incorrect!</p>");
should have been
$("#log").html(data.emailaddr);
}else{
$("log").html("<p>Your login details are incorrect!</p>");
diafol
Rhod Gilbert Fan (ardav)
7,796 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080