Does work with Mozilla.... Regards, Karl
Free Software: "You don't pay back, you pay forward." -- Robert A. Heinlein ---------------------------<snip>------------------- <?php /* Example of how to do a "please wait" message while a web page loads. * * May 28, 2003 * * Karl O. Pinc <kop AT meme DOT com> * * This code does not work with Microsoft's Internet Explorer. * (I suspect they want you to use their DHTML instead of the * W3/RFC standards. Unfortunately for them, javascript will do * the same thing and is more popular.) * * This technique can be adapted to send files along with a web page, * send many successive pages, send many alternative representations of * the same content, and so forth. (RFC 1341 is your friend.) * * The idea is to send two complete web pages in response to a single * client request. The first page has the "please wait" message, the * second is the data we want to deliver. We send two pages by returning * multipart/mixed mime document, each page being a separate part. * * For this page to work with apache/php the php short_open_tag configuration * directive must be set to "off", so the xml declaration is passed to the * client. Put "php_flag short_open_tag off" (in a <Directory> directive?) * in /etc/httpd/conf/httpd.conf or a .htaccess file. * * Note that this page relies on the w3.org site for the * xhtml dtd declaration. If you want to be stand-alone, copy * the document to your own server and adjust the URLs in the doctype * declaration. (The xmlns namespace in the "head" tag is a string * identifying the namespace, not a document.) * * As coded this page needs a (possibly empty) CSS file named 'markup.css' * in this file's parent directory. See: * http://www.w3.org/TR/REC-html40/present/styles.html * for more information. * * Technique from "The Linux Journal, Issue 82", "Web Servers and * Dynamic Content", http://www.linuxjournal.com/article.php?sid=4386, the * section titled "Pushing Continual Updates to the Browser". * See also section 7.2 of RFC 1341, nicely formatted at: * http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html */ // // Some constants // // The RFC is finicky, it wants carriage-return, line-feed as EOL // in mime documents. define(CRLF, "\r\n"); // The canonical name of the UTF-8 (us-ascii superset) encoding. define(UTF8, 'UTF-8'); // // Generate 70 characters to use for a boundary string. The boundary generated // is the most random allowed under RFC1341. The odds are // _long_ that the string won't occur elsewhere in the HTML. // // Note the space is last! define(BCHARS , "'()+,./01234567890:=?_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "); define(BCHARS_LAST_POS, 74); // indexed zero relative define(BCHARSNOSPACE_LAST_POS, 73); // 74 chars before the space $BOUNDARY = ''; for ($i = 1; $i <= 69; $i++) { // substr() is likely at least as fast as a php array reference. $BOUNDARY .= substr(BCHARS, rand(0, BCHARS_LAST_POS), 1); } $BOUNDARY .= substr(BCHARS, rand(0, BCHARSNOSPACE_LAST_POS), 1); // // Other initialization -- make more 'constant's. // $DELIMITER = CRLF . '--' . $BOUNDARY . CRLF; $CLOSE_DELIMITER = CRLF . '--' . $BOUNDARY . '--'; $CONTENT_HEADER = 'Content-type: text/html; charset=' . UTF8 . CRLF . 'Content-Style-Type: text/css' . CRLF . CRLF; // Note that we just assumed that all the parts are the same mime type and // encoding. This does not have to be the case. // Another possibility for a mime type is "text/plain", if that // floats your boat. You can also use various mime headers to // send files to the client and so forth. // // Have the server tell the client we'll be sending a multipart mime document. // // (Recall, header() _must_ be called before any output is sent. Check // those require()-s and include()-s that might be above to be sure // they don't generate output!) // (Old-time netscape used multipart/x-mixed-replace, but mozilla // works straight from the RFC recommendation.) header("Content-Type: multipart/mixed; boundary=\"$BOUNDARY\""); // // Test the client's implementation of multipart/mixed. // (If you're trying to get IE to work, remove this and the // other test output in the epilogue.) // ?> All output before the first boundary delimiter is preamble and should be ignored by the browser. If you can see this, your browser is not RFC 1341 compliant. <?php // // The first page to display. // // First, encapsulation as mime message, then the body, which includes // the requisite meta information about html version, encoding, etc. to // be standards compliant. (This meets XHTML 1.0, Strict.) print($DELIMITER); print($CONTENT_HEADER); // Note, the \n trailing the ? > is part of the ? > tag and not sent to client. ?> <?xml version="1.0" encoding="<?php print(UTF8); ?>"?> <?xml-stylesheet type="text/css" href="markup.css"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <link type="text/css" rel="stylesheet" href="markup.css"></link> <title>Test page -- waiting</title> </head> <body> <p> Please wait while our computer does something important sounding.... </p> </body> </html> <?php // Finish the encapsulation of the first page. print($DELIMITER); // Send the first page. flush(); // Wait 7 seconds, so the user has time to read the first page. sleep(7); // // Second page to display. // print($CONTENT_HEADER); // Note, the \n trailing the ? > is part of the ? > tag and not sent to client. ?> <?xml version="1.0" encoding="<?php print(UTF8); ?>"?> <?xml-stylesheet type="text/css" href="markup.css"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <link type="text/css" rel="stylesheet" href="markup.css"></link> <title>Test page</title> </head> <body> <p> All done. Ain't you glad you waited? </p> </body> </html> <?php // Finish the second page. print($CLOSE_DELIMITER); // // Just for grins, continue checking the client's rfc conformance. // flush(); // Send the second page. // Note, the \n trailing the ? > is part of the ? > tag and not sent to client. ?> All output after the closing boundary delimiter is epilogue and should be ignored by the browser. If you can see this, your browser is not RFC 1341 compliant. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php