PHP detects whether the user is shutting down the browser, PHP detects the user's browser _php tutorial

Source: Internet
Author: User
Tags php error

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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.