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.
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
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.
查看http://www.webmasterworld.com/forum88/1225.htm您将使用PHP的header()函数发送标题(必须在任何其他输出之前调用),但在使用之前/期间使用您的函数呼叫。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.