teynon Posted May 29, 2010 Share Posted May 29, 2010 Ok, so here's the story. I have created a very large program. This program has grown way beyond a one person project. I want to run all variables through a validate function before it is sent to the user. The problem is the program is so large, that it would take me a very long time to do that. Now I know one option is to make a function like "function output(value) { // do validate and echo }". But, that would mean I have to go through and modify all the echo statements in my code. That too, would take a very long time. So, what I'd like to know, is if there is a way to append a function to the echo construct? Kind of like register_shutdown_function, only something like register_construct_function(echo, MyFunction)... Or if anyone has another way, that would be awesome. Quote Link to comment https://forums.phpfreaks.com/topic/203297-modify-php-echo-command/ Share on other sites More sharing options...
Bladescope Posted May 29, 2010 Share Posted May 29, 2010 Or if anyone has another way, that would be awesome. Search and replace tool. Quote Link to comment https://forums.phpfreaks.com/topic/203297-modify-php-echo-command/#findComment-1065118 Share on other sites More sharing options...
teynon Posted May 29, 2010 Author Share Posted May 29, 2010 Search and replace over 1000+ files: echo "blah"; Even if I search for echo, I can only replace it to be like: validateOutput("blah"; Then I would have to manually add that. I'm trying to save myself about a week of work for a simple function. Quote Link to comment https://forums.phpfreaks.com/topic/203297-modify-php-echo-command/#findComment-1065121 Share on other sites More sharing options...
teynon Posted May 29, 2010 Author Share Posted May 29, 2010 For the record, all my input is validated, but the organization adopting the software uses "Fortify" to scan reports and that report says that it is sending unvalidated data to the web browser. Quote Link to comment https://forums.phpfreaks.com/topic/203297-modify-php-echo-command/#findComment-1065133 Share on other sites More sharing options...
trq Posted May 30, 2010 Share Posted May 30, 2010 You could wrap your entire application so that all output would be caught in a buffer. Just set the auto_prepend_file directive within your php.ini to point to a file containing.... <?php ob_start(); ?> Then use the auto_append_file directive to point to another script that captures the output into a string, you can then do whatever needs doing to the output all in one place. <?php $output = ob_get_contents(); // validate $output here echo $output; ?> Quote Link to comment https://forums.phpfreaks.com/topic/203297-modify-php-echo-command/#findComment-1065235 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.