Re: I'm really getting annoyed with PHP

From: Date: Thu, 24 Jul 2003 19:54:49 +0000
Subject: Re: I'm really getting annoyed with PHP
References: 1 2 3 4 5 6  Groups: php.general 
Request: Send a blank email to php-general+get-156731@lists.php.net to get a copy of this message
"Zerof" <zerof@terra.com.br> wrote in message news:20030724132559.28411.qmail@pb1.pair.com... > You are absolutely right, exit, quits my script, this let me use an independent script to > handle the headers. if used with conditional calls. . > ---- > zerof > ----- > "Comex" <ng@xemoc.cjb.net> escreveu na mensagem > news:20030724130500.12089.qmail@pb1.pair.com... > > <20030724130309.8752.qmail@pb1.pair.com> > ------------- > > Why? AFAIK, exit quits the script, exactly what you want if you want to redirect. > ----------- Zerof, Comex is absolutely correct. exit() should almost always be used in conjucntion with header("Location: "). I would be interested in learning what "collateral effects" you see when doing so. By any logic exit() should reduce the number of adverse effects when using header() redirects. Consider this example.. <? if($i==10){ header("Location: $nextpage"); } $_SESSION['i'] = $i; ?> If we were to employ this code $i would be set to the session even if header() was called and the user was redirected. PHP does not care that another script has been launched and happily continues to execute this script. Is this really a desirable effect? No.. surely not. Instead what we should do is exit the script after redirecting the user. <? if($i==10) { header("Location: $nextpage"); exit; } $_SESSION['i'] = $i; ?> Now we're safe becuase nothing beyond the header() call is going to execute. Obviously this is an extraordinarily simple example. But most scripts are not so straight forward. If you don't exit after a header redirect you could be causing yourself one hell of a headache. Be wise and have one script running at one time. - Kevin

« previous php.general (#156731) next »