PHP include - quick question

Discussion in 'PHP' started by oo7ml, Dec 6, 2007.

  1. #1
    I want to add an include to all of my pages on my site. The file i want to include is called code.php which just simply contains javascript for google analytics.

    My Question is: there is no PHP code in code.php (not even php tags around the javascript) so is it ok to call the include file (code.php) a .php file even though there is no php code it at all

    I just out this into all of my pages where i wanted to include the JS code
    <?php include("code.php");?>
    PHP:
    Thanks in advance
     
    oo7ml, Dec 6, 2007 IP
  2. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #2
    yep, it is definitely allowed, php is a very loose language and you can even include a php file that only had html on it :)
     
    serialCoder, Dec 6, 2007 IP
  3. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #3
    I do since long exactly the same - to (PHP)-SSI my adsense into each page - its an ideal way to create a highly sophisticated system of adsense channels to optimize your ads, to change ads by changing a few files only without touching the pages, by adding banners ... almost like you would using an adserver.
    but I gave the files to include a difference file-extension .tpl to make my life easier - but any other extension may work as well. php looks like code, tpl or other extensions is for text - it makes YOUR life easier later on to see at a glance from file extensions what content is where.

    hence
    basically your .php also should work as well

    one last point - I just solved last night - each such included adsense file will create a local server call = entry in your log file.

    with high traffic sites a lot of additional HDD-writing ( in my case some 120k/day log lines just for such) access that you may omit with proper code from being written to log files for better clarity of log files.

    since you do such procedure, it means you most likely have a bigger site and the SSI saves you time and work - hence if you have your own dedicated server now or later you may omit logging local server requests for such file requests as well.

    btw:
    my adsense SSI system was the beginning of serious adsense optimization leading to a near double in $ earlier this year. take your time when choosing the correct page placements of your SSI - your $ will reward you.
     
    hans, Dec 6, 2007 IP
  4. oo7ml

    oo7ml Well-Known Member

    Messages:
    656
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #4
    thanks guys
     
    oo7ml, Dec 6, 2007 IP
  5. oo7ml

    oo7ml Well-Known Member

    Messages:
    656
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #5
    WOW, thanks a million for all your help, i really appreciate it
     
    oo7ml, Dec 6, 2007 IP
  6. Gawk

    Gawk Peon

    Messages:
    427
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You may also want to consider php's auto_prepend_file method, this effectively includes a file at the beginning of every page handled by the php engine. It saves having to add the include code into every php page on your site.

    There is an example of how to use it in my blog...
    http://www.imblogingit.com/2007/11/27/pulsating/google-301-redirect-for-multiple-domains-the-php-answer/
     
    Gawk, Dec 6, 2007 IP
  7. oo7ml

    oo7ml Well-Known Member

    Messages:
    656
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #7
    thanks again
     
    oo7ml, Dec 6, 2007 IP