At 11:05 AM 2/6/2006, tedd wrote:
This might seem like a odd question, but in php I can leave a script
by "exit;" But, how can I also close the html page that contains the script?
I know that I can close the page many different ways via a user
actions, but how can I close it from within a conditional php statement?
Tedd,
There's a disjunction between the background pre-processing of a
server-side script and the real-[human]-time execution of a
client-side script. By the time we see the web page in our browser,
chances are the server-side script has long since completed its execution.
Therefore, rather than thinking of evoking actions to occur during
PHP processing, you'll want to ask, "What kind of page can I download
to the browser that will create the effect I want?" Imagine planting
something in your pyramid that will surprise archaeologists a
thousand years hence. You don't want the door to swivel now (PHP),
you want to plant a trap that will cause the door to swivel when
eventually someone hits the tripwire (JavaScript).
If PHP logic determines that the browser window should be closed, you
can download a very simple HTML page that contains two things:
a) JavaScript window.close(). This will execute only if client-side
scripting is enabled in the browser, and it will close the window
automatically only if it's a child window that had been opened by a
parent. If the window doesn't know that it has a parent, it will
prompt the user asking whether or not to close. The user can decline
that request; there's no way to force their hand.*
b) A text message declaring the session closed to be displayed if
JavaScript isn't running.
Another application of PHP-generated-JavaScript is to display an
alert. Say you've got a form that's submitted but rejected
server-side. PHP can download a new version of the input form
including an error message built into the page. That same message
can be written into a JavaScript alert() statement that's set to
execute when the page has downloaded. It's just an extra way of
catching the user's attention.
* If you really need to close your application and prevent the user
from continuing that session, you can do this by setting a $_SESSION
variable in PHP that your pages will take as a cue to begin a fresh
session or redirect to Oz.
Regards,
Paul
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php