Sorry guys ... you're right! A little code will help us all :) suppose my script is script.php
in html script.php i put
$(window).bind('load', function(){ $.post(PATHTOLOCK.php); }); $(window).bind('unload', function(){ $.post(PATHTOUNLOCK.php); });
In the PATHTOLOCK.php file, I do this:
$_SESSION['flag']=true;
And in the PATHTOUNLOCK.php file, I do this:
$_SESSION['flag']=false;
At the beginning of script.php I will put
if($_SESSION['flag']==true){ echo "error";exit; }
If I open script.php in two windows / tabs, everything works fine. If I refresh the page, this will not work, because I assume that the sequence of events is as follows:
- click on update
- the unload event is not raised because the page is not completely abandoned
- script.php reloads
- check at the beginning of script.php is not performed because flag = true
- script.php goes about error
- the unload event is dispatched because the page is left and the flag = false
- click on update
- now it works!
etc .... every two updates it works!
source share