php session variables not updating

大憨熊 提交于 2020-01-06 01:51:09

问题


I have a php session variable and I update it in a page and access it in different page, when the variable comes to a threshold I reset it to zero and increment it according to the number of files uploaded.

The problem is after it reaches to the threshold when I reset and reload the page again the file that I access the session variable not updating and shows zero though the files are uploaded.

But actually the session variable is incrementing in the other page. It shows the real value(the value incremented) after only reloading twice.

I want to know why it happens.


回答1:


First of all, It is critical to show your codes for your question, but for this particular one, the problem is that you are using session variables right in the file that you updated them. sessions load before anything in the page so, when you update them they are already loaded and although they have changed, their value is still the same in current page. To prevent that, you need to either go to another page after updating the session or put a redirect after your session change statement if it is necessary to stay in same address, like this:

<?php
if(threshold){
$_SESSION['your_session']='your new value';
header('LOCATION sample.php');
}
?>


来源:https://stackoverflow.com/questions/29388126/php-session-variables-not-updating

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!