php $_SESSION restableciendo cada 10 segundos
Frecuentes
Visto 175 veces
0
El problema que tengo es este:
I'm setting a page number with php $_SESSION['page']
at the top of my 'home' page, then using Jquery to retrieve data from a php file using the $_SESSION['page']
for reference, and updating $_SESSION['page'] so that on the next call to the file i know where to pick up from...
However, every 10 seconds, the $_SESSION['page']
reverts to what i set it at originally on the 'home' page..? Here is the basic example.
'Home' page:
<?php
session_start();
$_SESSION['page']=1;
?>
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<script>
function get_stories(){
$.post("function.php", function(data){
$("#stories").append(data);
});
}
</script>
</head>
<body>
<button onmouseup="get_stories();">Get Stories</button>
<div id="stories"></div>
</body>
</html>
The function.php:
<?php
session_start();
$page = $_SESSION['page'];
//does some REALLY simple sql calls nothing editing the $_SESSION in anyway.
//formats the results and puts them in a variable $string
if(strlen($string)>0){ //if there was content
++$page;
}
$_SESSION['page']=$page;
print $string;
?>
Every ten second however.. my $_SESSION['page']
reverts back to 1 (what i set it as when my 'Home' page first opens).
I even made a test where all the function did was increment the $_SESSION['page']
and is still reverted every ten second...
0 Respuestas
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas php jquery session session-timeout or haz tu propia pregunta.
Have you verified you're sending the correct cookie/SID? You might get an entirely new session each call. - mabi
I believe so. The function is working properly and incrementing the $_SESSION['page'] just fine for the ten seconds. However just any $_SESSION variable that i set in the 'home' page revert back every ten seconds.. - user3040452
Easy to check: print
SID
to a log (or the page) and verify. You still might have a cookie lifetime of 10s or something. - mabiThat also doesn't seem to be the issue... My 'session.cookie_lifetime' is set to '0' Meaning it dies when the browser closes. All sessions set when the user logs in and such are fine. just this variable that is reset each time the visiter revisits the 'home' page reverts during the jquery call. its as if the jquery $.post() function is refreshing the page every ten seconds... - user3040452