techloop Posted June 12, 2011 Share Posted June 12, 2011 Hi all, I have a simple code that override some env vars but i need it to run before any other php code on every php execution. I would like to avoid any change of all php code (even if its only to include the include command). Any one knows of such way ? I dont mind overriding this vars on php configuration file but i dont have any control of it as its should work on even the most strict web hosting (that still allow env vars manipulation) Any alternatives ? Thanks, TL Quote Link to comment https://forums.phpfreaks.com/topic/239158-execute-my-php-code-before-every-php-call/ Share on other sites More sharing options...
xyph Posted June 12, 2011 Share Posted June 12, 2011 That's the only way. PHP won't execute code that isn't there. This would create insane debugging issues. Quote Link to comment https://forums.phpfreaks.com/topic/239158-execute-my-php-code-before-every-php-call/#findComment-1228747 Share on other sites More sharing options...
techloop Posted June 12, 2011 Author Share Posted June 12, 2011 still, i pretty sure there is another way to do this Quote Link to comment https://forums.phpfreaks.com/topic/239158-execute-my-php-code-before-every-php-call/#findComment-1228750 Share on other sites More sharing options...
mikesta707 Posted June 12, 2011 Share Posted June 12, 2011 There is no way I know of to execute PHP code without telling PHP to execute it. Do you not have some sort of config file that is included on every page you could add this code? Quote Link to comment https://forums.phpfreaks.com/topic/239158-execute-my-php-code-before-every-php-call/#findComment-1228753 Share on other sites More sharing options...
xyph Posted June 12, 2011 Share Posted June 12, 2011 What's to stop this code from getting executed twice when you include files? You could code a custom PHP extension, but you wouldn't be coding it in PHP. You would also need direct access to your PHP engine. Quote Link to comment https://forums.phpfreaks.com/topic/239158-execute-my-php-code-before-every-php-call/#findComment-1228761 Share on other sites More sharing options...
techloop Posted June 12, 2011 Author Share Posted June 12, 2011 OK, so i might have been misunderstood. The problem that i faced with is as follow: 1.There is a hardware that manipulates some of HTTP core information such as the client's IP address. I know that this hardware is not unique and there are even cloud base services that do this. 2. the real information (the real IP of the client on my example) is stored on the HTTP header 3. i need to override some $ENVs (e.g. $_ENV["REMOTE_ADDR"] and $_SERVER["REMOTE_ADDR"]) 4. because those vars are "re-generated" on each php execution i would like that my code that "fix" the information to be executed before any other code. I hope that this clear my problem and that someone will guide me of the right way to overcome it Thanks TL Quote Link to comment https://forums.phpfreaks.com/topic/239158-execute-my-php-code-before-every-php-call/#findComment-1228768 Share on other sites More sharing options...
xyph Posted June 12, 2011 Share Posted June 12, 2011 Include it at the top of each page, after any session or cookie calls. Quote Link to comment https://forums.phpfreaks.com/topic/239158-execute-my-php-code-before-every-php-call/#findComment-1228773 Share on other sites More sharing options...
techloop Posted June 12, 2011 Author Share Posted June 12, 2011 no go i don't know how will run it on what code. this should be a generic solution for all php code and for all this hardware users. Quote Link to comment https://forums.phpfreaks.com/topic/239158-execute-my-php-code-before-every-php-call/#findComment-1228775 Share on other sites More sharing options...
xyph Posted June 12, 2011 Share Posted June 12, 2011 Then code an extension Quote Link to comment https://forums.phpfreaks.com/topic/239158-execute-my-php-code-before-every-php-call/#findComment-1228784 Share on other sites More sharing options...
techloop Posted June 13, 2011 Author Share Posted June 13, 2011 Another way that i found out is auto_prepend_file that seems to be doing what I need but for some reason it does not always work. is any one use it or can give me some inputs ? Quote Link to comment https://forums.phpfreaks.com/topic/239158-execute-my-php-code-before-every-php-call/#findComment-1228951 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.