Injecting code in every page on localhost

Discussion in 'Programming' started by RedDem0n, Oct 31, 2008.

  1. #1
    Is it possible with a script to automatically insert a few codes? Basically what the whole issue is...There's like a million .cfm pages..and I'd like my analytic stats to be more accurate, and would like to add the google analytic codes to all of these pages without having to go through each one of them manually and adding it in..Is that possible ?
     
    RedDem0n, Oct 31, 2008 IP
  2. robhustle

    robhustle Peon

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Depending on what version of ColdFusion you are running, there are a couple options.

    Application.cfm
    This file gets executed each time a user requests a page. You can insert code here that you want to run each time. Note that the code in application.cfm is executed before the cfm page, so if you need the code injected at the end of the request, see below.

    Onrequestend.cfm
    This file gets executed at the end of each request. Anything you want inserted after the page processes, insert it here.

    Application.cfc
    If you use application.cfc instead of application.cfm, then you can put the code you want executed insde the OnRequestStart(), OnRequest(), or OnRequestEnd() methods.
     
    robhustle, Oct 31, 2008 IP
  3. dshuck

    dshuck Peon

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This is another example of why people should be using the MVC design pattern, and making use of one of the powerful frameworks that our community has been gifted with. On most modern CF applications you would simply go into your layout view and place the code in a single spot where you want it and all appropriate pages would receive it. Please people... start using Fusebox, Mach-II, Model Glue, or ColdBox. They are all amazing frameworks and will make you apps much better!
     
    dshuck, Nov 1, 2008 IP
  4. RedDem0n

    RedDem0n Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thank you for your response guys, I will check both out and update with what I come up with. Right now the onrequestend.cfm looks like the perfect, and quick solution for me.

    Update: Working great, thanks again. :)
     
    RedDem0n, Nov 1, 2008 IP
  5. robhustle

    robhustle Peon

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Philosophically, you might be right. But "Learn a framework" doesn't offer much practical help.
     
    robhustle, Nov 1, 2008 IP