| 
	
 | 
 Posted by Colin McKinnon on 06/22/06 22:17 
maya wrote: 
 
> yes I know, this has been asked many times, but I don't quite the 
> answers: usu. answers are to put the redirect code -- in my case 
>  
>   $URL = 
> "out.php?msg=selected+records+have+been+deleted+from+the+database."; 
>   header("Location: $URL"); 
>  
> BEFORE any HTML output (does this include 'echo' output's?) 
>  
 
Yes - everything outside of <?php ... ?> and every print and echo inside. 
 
> but: if, like in my case, for example, I delete data (passed in req) 
> from db  
 
So how does that cause output to the browser? 
 
> THEN I redirect pg back to referer, how can I put redirect code  
> BEFORE anything else?   
 
Using a POST/GET redirection pattern is messy even when you know what you 
are doing. And if you knew what you were doing you wouldn't use 
header("Location:...") for the redirection like that. It may have become 
standard practice for HTTP/1.0 but just plain wrong for HTTP/1.1. Have a 
google for discussion on the topic. 
 
> <html><head>css.. etc.. </head><body> 
> php: do db stuff...  then: 
> mysql_close($conn); 
> echo "<br><br><b>connection to db closed.</b><br><br><br>\n\n"; 
> $URL = 
> "out.php?msg=selected+records+have+been+deleted+from+the+database."; 
> header("Location: $URL"); ?> 
> </body> 
> </html> 
> 
 
Try doing the php stuff before you do <html>. You can work around it by 
using output buffering but you're just digging a bigger hole for yourself 
if you do by making your code more complex and jumbled than it needs to be. 
 
 > (this is not a serious problem since can do with JavaScript, but just 
> wondering what the deal is here... in Java you do redirect with RESPONSE 
> object,  
 
php != java 
php != asp 
php != perl 
php != ecmascript 
php != Visual BASIC 
 
If you want to write a framework of objects so it behaves similarly - then 
do so - its quite possible. You can even recreate those fun null reference 
errors (memory leaks, application server recycles, and horrendous build / 
deployment cycles are much harder to emulate though). 
 
Or a better idea might be to go find a templating system. 
 
C.
 
  
Navigation:
[Reply to this message] 
 |