Forum Moderators: martinibuster

Message Too Old, No Replies

How to include Google adsense code which is in an external file?

I want to include Google adsense code from an external file.

         

mahidhar

1:38 am on Sep 2, 2004 (gmt 0)

10+ Year Member



Hi,

I have a site which has around 200 static HTML pages. I use adsense in all these pages. The problem is , If I want to change the color or style of the ads, I have to modify all the 200 html pages. To avoid this I am planning to put the adsense code in an external file and include that file from the 200 HTML pages by using Java Script. I don't know exactly how to do it. Please help me out.

moltar

1:49 am on Sep 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



On Apache web server you could use SSI:
<!--#include virtual="/path/to/code.html" -->

in PHP you can use include() function:

include ("/path/to/code.html");

btas2

2:07 am on Sep 2, 2004 (gmt 0)

10+ Year Member



I asked the same question some time ago and the general opion was that putting AdSense code in a Javascript file was against the terms of service.

Server Side includes are OK (if your host supports them).

To use PHP wouldn't you have to convert all your .html pages to .php, which would be a pain.

I'm still running Adsense from Javascript files on some pages. So far either they haven't noticed or they don't mind. I'm not sure which!

The Javascript file is just a series of "document.write" statements that spit out the AdSense code. Easy to do, but if it is against the TOS, you're taking a risk.

Marcia

2:20 am on Sep 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>>To use PHP wouldn't you have to convert all your .html pages to .php

No, you can parse HTML pages as PHP.

mahidhar

4:07 am on Sep 2, 2004 (gmt 0)

10+ Year Member



Hi,

Thanks for your help. How can I parse HTML pages to PHP. Is there any freeware for this?

MrAnchovy

4:17 am on Sep 2, 2004 (gmt 0)

10+ Year Member



To use PHP wouldn't you have to convert all your .html pages to .php, which would be a pain.

A batch rename would make it easy... then of course, one would need to edit any direct links within the files to reflect any changes (which can also be done in mass w/ the right progs)

However... it's easier to do the following...

Thanks for your help. How can I parse HTML pages to PHP. Is there any freeware for this?

Add the following to your .htaccess file in the root dir of your website.... assuming your are on a *nix box.

They are typically hidden... so try & download it first via ftp to make sure you aren't writing over an existing .htaccess file w/ needed settings:

AddType application/x-httpd-php .html
AddHandler x-httpd-php .html

If you want more info... it's most likely already been covered.
[webmasterworld.com...]
[webmasterworld.com...]
[webmasterworld.com...]

TampaLou

6:40 pm on Sep 2, 2004 (gmt 0)

10+ Year Member



You also have the option of changing your .html files to .shtml files and foregoing the .php route. It can be a hassle to do that with your files now, but as someone who did that with 750+, let me tell you that from my experience it was well worth the effort.