Hello friends, Have a question here. I want to execute a particular chunk of PHP code when a user closes the browser window or he refreshes the webpage. How it can be done in PHP. Let me explain with an example. A a random number is generated and passed it to a variable(say $x) when a user accesses the webpage for the first time This variable's value must be preserved till user closes the webpage or she refreshes. This webpage includes a form whose input is compared against the variable $x. This form is a self directed one - action = "" Form code 1. <form action = "" method = "post"> 2. Number : <input type = "text" name = "name" /> 3. <input type = "submit" /> 4. </form> PHP: User can try to match the variable $x with "Number" say 10 number of times. Needs are: 1) The variable $x must not change its value between form submissions. 2) When page refresh/close occurs $x must be destoyed. How it can be done. Regards, Vinod
Here is a link that might help you. I'm not entirely sure what exactly you want the page to do but I'm sure you would be able to handle it with sessions or directly with a database. http://www.php.net/manual/en/book.session.php
Variables are always "destroyed" when you refresh/close the page. The easiest way would be to use PHP session : http://lv.php.net/session
That's unfortunate, since there's no way to guarantee you will get to run your code when the user closes the browser window or navigates away to a new site.
No, not all of them, most of them. Superglobal arrays will stay obviously. You can use xajax libary to register the PHP functions then use Javascript to calle them when ever the hell you want. xajaxproject.org