Search code examples
phpsecurityhook

php hook core functions


I want to hook before execution / or replace standard core functions, for example I'm going to prevent both include and require access to any scripts. Is there any way to make it without any extra dll's? Or in another case is_array($myarr); I would hook at array($myarr) === $myarr; (looks like it is faster) to avoid creating extra classes and functions.

And how could I prevent all PHP executions after some moment? I have HTML templates with PHP parts <?=$myvar?> I want to prevent short syntax and execution at all when my script ends work, what do I have to try?


Solution

  • About hooks to standart functions: there is no way to do that without external modules. APD PECL module will do the job.

    rename_function('require', 'internal_require'); // saving reference to original function
    override_function('require', '$filename', 
                      'print "require called"; internal_require($filename);');
    

    Second question is not very clear. Do you want to hook on standart is_array function, to array() lexical construct or (array) type casting?

    About stopping php interpretation: have a look at __halt_compiler function. But keep in mind that succeeding blocks of php will be just embedded in HTML (thus visible to everybody).