Does code execute after header (); ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Does code execute after header (); ?

Post by Chris Corbyn »

Hi,

I've got a download page which redirects to files based on the input in a form.

Redirect uses the header function but I also wish to fwrite to a log file from this same page. Will the fwrite function be carried out even after redirect has occurred?

Thanks
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Why don't you try it? ;)
Image Image
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I was trying it for ages and I couldn't get it to work so I thought I'd post in here to see if it was a lost cause but I've got it working now anyway so i guess the answer is "Yes", code after the header will be executed but not before the header.

Thanks anyway :-)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

sorry, that's wrong. Code before the header will be executed too so long as it's not echo or print
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

It will also work when they there is output (echo or print).
But this will make the header function fail (because headers have to be outputted before anything else gets outputted). In case you are using output buffering, you could work around that "problem"
Post Reply