A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearCall a function before outputting headers in PHP? - page 1
User InfoPosts
Call a function before outputting headers in PHP?#1
Is there any way to have PHP automatically call a function, before a script outputs any HTTP headers?

I'm looking for something like register-shutdown-function, but to register a function that's called before the output is already sent, not after. I want my function to send a header, so I need something that's called earlier.

posted date: 2008-12-24 11:22:00


Re: Call a function before outputting headers in PHP?#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-24 11:22:01


Re: Call a function before outputting headers in PHP?#3
Check out http://www.webmasterworld.com/forum88/1225.htmYou'd be using PHP's header() function to send a header (which must be called before any other output), but using your function before/during the call.

posted date: 2008-12-24 11:27:00


Re: Call a function before outputting headers in PHP?#4
Thanks, but that's not quite what I'm looking for. I could always call header() manually, but I'm trying to avoid making a change to every place where I return output.

posted date: 2008-12-24 11:39:00


Re: Call a function before outputting headers in PHP?#5
In other words, I want the function to be evaluated as late as possible, before the headers are sent. I don't want to start sending the headers earlier than I was before.

posted date: 2008-12-24 11:41:00


Re: Call a function before outputting headers in PHP?#6
You could also trap everything with ob_start and then register a callback function to be used when you send the page with ob_end_flush. Check out the PHP manual for OB_START

posted date: 2008-12-24 11:43:00


Re: Call a function before outputting headers in PHP?#7
I don't know if it is what you are looking for but you might want to investigate using auto_prepend_file in your php.ini or setting it in an .htaccess file. If you set an auto_prepend_file it will automatically include that file before running each script.auto_prepend_file

posted date: 2008-12-24 18:14:00


Re: Call a function before outputting headers in PHP?#8
Looks like this is about as close as you can get.

posted date: 2009-08-23 07:59:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.