I have a $_SESSION created in php. One of its values is the last activity stamp. The $_SESSION['LAST_ACTIVITY'] is being updated in php part of the code, and according to the console output, I can see it is changed correctly: The previous php function is being called from jQuery with $ajax when switching between the nav pane tabs, posting to php page and getting the $_SESSION parameter updated (I can see it in network response correct after echo Session updated). However the What am I missing, why the php echo returns the same value for the variable? Tried in several browsers, thought it is some sort of cache issue, even tried to echo time(). The same output. First time works correctly, then ceases to update. Edit Answer This line won't change between ajax calls: You should replace the php code by the data you receive in the ajax response. To set an initial value, you can "write" a javascript variable and take the value from there in To do this, at the bottom of the body, you can set: Then you can get the initial value from myPhpVrs.lastActivity, and any update from the ajax response. Aditional note: Consder escaping php code to avoid javascript injection.
I'd like to show the stamp on the $action = $_POST['action'];
switch ($action) {
case 'login': DoLogin(); break;
case 'logout': DoLogout(); break;
case 'update': updateSessionActivity(); break;
default: $errmsg_arr[] = 'Unknown action'; $errflag = true;
}
function updateSessionActivity()
{
if (isset($_SESSION['LAST_ACTIVITY'])) {
$_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp
}
echo "Session updated: ".$_SESSION['LAST_ACTIVITY'];
}
?>
I was asked to edit the question to specify how it differs from what supposed to be the same questions.
I would like to point at the fact that the answer and question provided as duplicate are way too differ from the problem in my question.
I do have php code executed while surfing on the page and I DO have my variables changed. Now after the answer I have them also changed on the front page and they are not "hardcoded", whatever that means.
$("#page_header_cont").html(" Last activity: " + ""
$(document).ready()
;
Sunday, 6 May 2018
javascript alert for changing php variable
element on the page.
element's html with ID "page_header_cont" gets updated only once (first time I switch to another tab pane) and never changes after, although I continue to switch between the tabs and see that POST works correctly with variable updated.
Subscribe to:
Post Comments (Atom)
casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV
In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...
-
Parse error: syntax error, unexpected '(', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' ...
-
I'm using Simple HTML DOM to extract data from a HTML document, and I have a couple of issues that I need some help with. On the line th...
-
The whole error output being: LNK2019 unresolved external symbol wWinMain referenced in function "int __cdecl __scrt_common_main_seh(vo...
No comments:
Post a Comment