I have a custom script that since my move to Drupal has been hard-coded in the core index.php file.
I realize this is not the Drupal way and it has been a pain to ensure that this code is added every time drupal core is updated...
To correct this, I wish to turn it into a module, however, the functionality of this code has to specifically be loaded before anything else as I need to be able to perform a meta redirect if needed....
Basically I have the script check to see if the URL has a variable stored which triggers the redirect, so if a different website is linking to mine with this variable, the script then redirects the user to whatever page on my site I want... there are other things the script does, like logging the referral site and such, but I don't think that it is relevant to this question.
While I have been playing with altering strings and links with custom Drupal modules, I have no idea what hook I would use to implement this, or even if its possible to do with Drupal other than hacking up the index.php
Any ideas?
Comments
you can take a look at hook_init
hook_init (http://api.drupal.org/api/function/hook_init/6) called for each page load in drupal,
If you want even early than hook_init, you can use hook_boot(http://api.drupal.org/api/function/hook_boot), may this help you.
Regards,
Rajan
hook_page_build() in D7
Use hook_page_build() instead. hook_init is run for every request, including ajax callbacks etc., and why would you want to be inserting arbitrary javascript for those?
Metatag should be in core.
drupal_add_js
Once you decide which hook works for you, add the JS using drupal_add_js script