|
użytkowników online: 68
|
OPINIE UŻYTKOWNIKÓW
|
Porady zamieszczone tutaj przez Darka są pomocne w wielu chwilach. Wielokrotnie tworząc jakiś złożony serwis korzystam z tych porad. Można by tworzyć samemu te skrypty, ale tak naprawdę czy nie lepiej jest wziąć skrypt z tej strony i zmodyfikowac go dla swoich potrzeb? Wprawdzie możemy taki skrypt napisać sami, ale po co, skoro stracimy czas na coś, co ktoś juz napisał, przetestował i może zagwarantować, że działa poprawnie. Któryś raz z rzędu opłacam abonament i nie raz jeszcze opłacę. Kawał dobrej roboty i ogrom wiedzy w jednym miejscu.
Piotr Karamański Design Studio
|
|
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net
[Spis]
[A]
[B]
[C]
[D]
[E]
[F]
[G]
[H]
[I]
[J]
[K]
[L]
[M]
[N]
[O]
[P]
[Q]
[R]
[S]
[T]
[U]
[V]
[X]
[W]
[Z]
exit (PHP 3, PHP 4, PHP 5 ) exit -- Output a message and terminate the current script Descriptionvoid exit ( [string status] ) void exit ( int status ) Notatka:
This is not a real function, but a language construct.
Notatka:
PHP >= 4.2.0 does NOT print the status
if it is an integer.
The exit() function terminates execution of
the script. It prints status just before exiting.
If status is an integer, that value
will also be used as the exit status. Exit statuses should be in the
range 0 to 254, the exit status 255 is reserved by PHP and shall not be
used. The status 0 is used to terminate the program successfully.
Przykład 1. exit() example |
<?php
$filename = '/path/to/data-file';
$file = fopen($filename, 'r')
or exit("unable to open file ($filename)");
?>
|
|
Przykład 2. exit() status example |
<?php
exit;
exit();
exit(0);
exit(1);
exit(0376); ?>
|
|
Notatka:
The die() function is an alias for
exit().
See also: register_shutdown_function().
User Contributed Notesfrancois at bonzon dot com
25-May-2005 03:42
With output buffering on, when sending headers that shouldn't have any data after them, be sure to erase the buffer before exit()ing the script! Like this:
<?php
ob_clean();
exit();
?>
If you don't erase the buffer, in case it was not empty, after sending the headers PHP will still send the buffer content to the browser.
I had Firefox show strange behavior with some of my pages, that it took me quite some time to debug. It was simply because my script was returning 304 Not Modified headers along with the start of an HTML page.
bfuchs at brgkepler dot at
25-Feb-2005 01:18
exit(); may also take Arguments like die();
For example:
exit("Error connecting to Database");
The function will return the given String to the user before it kills the script.
tatlar
31-Jan-2005 08:49
I have had problems using exit(); within PHP scripts that worked just fine on Apache 1.3.* but now fail since upgrading to Apache 2.0.*
Similar to other comments below, I switched all my exit(); calls to return(); and everything appears to work just fine.
OS is SuSE Linux. HTH helps someone - I have been frustrated for days in trying to figure why my scripts were failing.
chris at artimador dot com
25-Nov-2004 08:01
When using php as a SHELL scripting language, use die() instead of exit(). If using exit in php5, the script will continue to processes conditionals and other shell_exec functions after the die command.
nospam at mydomain dot com
27-Sep-2004 11:12
Using return instead of exit is to prefer when you want the script that you have included inside another script to die but continue to execute the main script.
// Radcliff
emils at tvnet dot lv
23-Aug-2003 05:14
Note, that using exit() will explicitly cause Roxen webserver to die, if PHP is used as Roxen SAPI module. There is no known workaround for that, except not to use exit(). CGI versions of PHP are not affected.
mbostrom at paragee dot com
26-Feb-2003 09:45
In PHP 4.3.1 (and possibly 4.3.0), running scripts from the command line works a lot better. This is probably because 4.3.x has a whole new CLI mode.
Specifically, exit status is now returned (to the shell) as you would expect. This is a godsend for writing embedded email processing scripts, as much email infrastructure (fetchmail, qmail, mutt, etc.) is dependant upon correctly returned status codes, and the inability to return a status code (as in PHP 4.2.x) is an insurmountable obstacle.
$_SERVER["argv"] is also always available in 4.3.x, I think, whereas in 4.2.x php.ini could prevent it from being available.
(On the downside, I had to ./configure --without-mysql in order to get 4.3.1 to compile on RedHat 8.0. Otherwise there was what looked like a fatal compile warning (that I might also have been able to ignore somehow).
The "fatal warning" FYI:
ext/mysql/libmysql/my_tempnam.o: In function `my_tempnam':
ext/mysql/libmysql/my_tempnam.c:103: the use of `tempnam' is dangerous, better use `mkstemp'
Changing the code from tempnam to mkstemp would probably not be overly complicated, but it is non-trivial.)
shaun at NOshatSPAM dot net
09-Aug-2002 01:13
return may be preferable to exit in certain situations, especially when dealing with the PHP binary and the shell.
I have a script which is the recipient of a mail alias, i.e. mail sent to that alias is piped to the script instead of being delivered to a mailbox. Using exit in this script resulted in the sender of the email getting a delivery failure notice. This was not the desired behavior, I wanted to silently discard messages which did not satisfy the script's requirements.
After several hours of trying to figure out what integer value I should pass to exit() to satisfy sendmail, I tried using return instead of exit. Worked like a charm. Sendmail didn't like exit but it was perfectly happy with return. So, if you're running into trouble with exit and other system binaries, try using return instead.
iamfast at tampabay dot rr dot com
14-Jul-2002 05:12
If you are working with images or something of the sort that is not html, and use auto appending, call exit before you close your php tag, so that the footer is not included, corrupting the end of the file.
--Nate
devinemke at devinemke dot com
11-Jan-2002 09:38
If you are using templates with numerous includes then exit() will end you script and your template will not complete (no </table>, </body>, </html> etc...). Rather than having complex nested conditional logic within your content, just create a "footer.php" file that closes all of your HTML and if you want to exit out of a script just include() the footer before you exit().
for example:
include ('header.php');
blah blah blah
if (!$mysql_connect) {
echo "unable to connect";
include ('footer.php');
exit;
}
blah blah blah
include ('footer.php');
|