PHP detects whether a user has closed the browser, PHP detects the user's browser
This example describes how PHP detects whether a user is shutting down a browser. Share to everyone for your reference, as follows:
1. Example 1
echo str_repeat ("", +); Ignore_user_abort (true); MyLog (' online '); while (true) { / * * 1, program ends connection_status 0 * 2, click the Browser stop button connection_ Status 1 * 3, timeout connection_status 2 */echo "test
\ n "; Note that the program must have output, otherwise the aborted state is not detected flush (); Sleep (1); if (Connection_status ()!=0) { mylog (' Offline '); Die (' End of the script '); }}function MyLog ($str) { $fp = fopen (' E:/abort.txt ', ' a '); $str = Date (' y-m-d h:i:s '). $str. " \ r \ n "; Fwrite ($fp, $str); Fclose ($FP);}
2. Example 2
function foo () {$s = ' connection_status '. Connection_status (); MyLog ($s);} register_shutdown_function (' foo ');//script Processing is complete or when exit () is Calledset_time_limit, for ($i =0; $i <10000000; $i + +) echo $i; function MyLog ($ STR) { $fp = fopen (' E:/abort.txt ', ' a '); $str = Date (' y-m-d h:i:s '). $str. " \ r \ n "; Fwrite ($fp, $str); Fclose ($FP);}
Read more about PHP related content readers can view the topic: "PHP Basic Grammar Introductory Tutorial", "PHP error and Exception handling method summary" and "PHP common functions and Skills summary"
I hope this article is helpful to you in PHP programming.
Articles you may be interested in:
- Php method for obtaining the name and version of the client browser (based on the Ecshop function)
- Use PHP and JavaScript to determine whether a request is from an in-browser
- PHP Judge Browser, Judge language code sharing
- PHP implementation read the mobile client browser class
- How PHP Gets the user browser version
- PHP 4 functions to output content to the browser summary
- How PHP prohibits browsers from using cached pages
- PHP export CSV data in the browser output provides an example of downloading or saving to a file
- PHP 2 ways to get browser information classes and client locations
http://www.bkjia.com/PHPjc/1099053.html www.bkjia.com true http://www.bkjia.com/PHPjc/1099053.html techarticle PHP detects whether a user is shutting down a browser, PHP detects a user's browser This example describes how PHP detects whether a user is shutting down a browser. Share to everyone for your reference, specific as ...