Is there anyway to create custom superglobal functions in php?
I’m on shared server. and I want to change my timezone setting in MySQL.
I have added SetEnv TZ America/Montreal to .htaccess in my root folder, but it only has effect for PHP and won’t affect MySQL NOW(), CURDATE(), CURTIME(). MySql still uses server’s TimeZone.
Now I am thinking to create a superglobals PHP functions for example:
function now() { return date("Y-m-d H:i:s"); }
Is there anyway to make this function accessible for every single PHP file in my server without include() it on every single php files?
I am using many many scripts, like wordpress, phpbb, affiliate script, etc. and I dont want to change every single now() to date('Y-m-d H:i:s'). It’s not efficient to do this, or use set time-zone on every first MySQL connection.
PHP has an ‘auto_prepend_file’ option, which basically acts like an automatic “include()”, but if you’re on shared hosting, this is most likely NOT an option – it applies to all of PHP, which means everyone else you’re sharing the server with will also get your code.
So basically, it boils down to “stop being lazy, and write out the
include()in each file”.