Forum Moderators: phranque

Message Too Old, No Replies

Help with an adsense problem

         

jaames

6:28 pm on Sep 5, 2005 (gmt 0)

10+ Year Member



How do I manage 100+ pgaes, with adsense on them?

I was told to use an “include” file, so instead of changing each add one by one I can do them all from the include file. Im confused, anyone know how I can make this work?

So does that mean I have to paste the include file code wherever I need the Adsense to appear?

I need help because I like to play around with the positions of the adsense, does that mean I have to go thought 100+ and change them manually? is it a necessary evil or there is an easier way?

activeco

7:31 pm on Sep 5, 2005 (gmt 0)

10+ Year Member



Learn PHP.

jaames

9:08 pm on Sep 5, 2005 (gmt 0)

10+ Year Member



They are in PHP pages. But I have 100+ pages of contents in PHP.

If i wanted to change the color of the adsense ads, i currently need to do it by editing 100+ pages. I've been told INCLUDE file its the way, thats why im seeking help.

Anyone can help me please?

activeco

10:08 pm on Sep 5, 2005 (gmt 0)

10+ Year Member



They are in PHP pages. But I have 100+ pages of contents in PHP.

If i wanted to change the color of the adsense ads, i currently need to do it by editing 100+ pages.

If they are written in PHP, I don't understand your problem.
Put (PHP properly formated) adsense code only in a file named say 'adsense.php'.
Remove the code itself from all of your pages and put this statement instead:

<?php
include 'adsense.php';
?>

Now, change only the file when you need it.

Jenstar

10:22 pm on Sep 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just be sure you do not change the AdSense javascript in the include file. AdSense support has stated you cannot make any changes to the javascript, even if the purpose is so that it can be added as an include.

activeco

10:29 pm on Sep 5, 2005 (gmt 0)

10+ Year Member



I need help because I like to play around with the positions of the adsense...

Regarding different positioning in 100's of pages, you'll first have to play a lot with PHP.

NoLimits

12:22 am on Sep 6, 2005 (gmt 0)

10+ Year Member



Going further on JenStar's statement. Specifically, you may have to put a \ in front of each quote to retain them in the actual source code produced after php is parsed.

RonS

1:06 am on Sep 6, 2005 (gmt 0)

10+ Year Member



Well, don't name the file "AdSense.php", and don't use a php include to bring it into your sourcecode.

Maybe try something like


printf("%s",file_get_contents("includes/googlead3.html"));

You can also load it into a variable and do the same thing:


$some_variable = file_get_contents("includes/googlead3.html");
printf("%s",$some_variable);

Where "includes" is a directory where ad source code files are stored.

That's a php solution that won't cause parsing, or need "\"s in front of every line.

Good luck.

activeco

5:07 am on Sep 6, 2005 (gmt 0)

10+ Year Member



Well, don't name the file "AdSense.php", and don't use a php include to bring it into your sourcecode.

Why is that?
What's wrong with the simple echo?

RonS

10:05 am on Sep 6, 2005 (gmt 0)

10+ Year Member



Nothing is wrong with using an "echo". I'm an old C programmer and it's just more natural to me to use a formatted output statement. "echo" would be just fine in this case.

The point was not to treat the adsense code like a .php file, causing it to be parsed.


The include() statement includes and evaluates the specified file.

Source: us2.php.net/manual/en/function.include.php , emphasis mine.

I hope this kind of url is ok per ToS, if not, I'm sure Jen will snip it out. It referred to a page of the php manual. Google "php manual include".

JeroenK

12:03 pm on Sep 6, 2005 (gmt 0)

10+ Year Member



Actually, I do use a .php file where I have all the Adsense code in, and I use include(); to get the ads in. I'm not a die-hard PHP coder (slef-thaught, just a few sites), but I found this technique really easy, and I have all my adsense codes into a single file which I can edit easily (even for example to remove all adsense code in case of click attacks in 1 go by emtpying the file!).

In all pages where I want an Adsense ad I put on the location of the ad the following code:

<?php include('_adsenseIncludes.php');?>

I use a _ for all my include files such as footers, headers, metatags etc so they are nicely grouped togheter in the top of my FTP client.

Then, in the _adsenseIncludes.php file I use if-statements to see what page I have, and then serve the Adsense code for that page. The next example I made for 3 types of pages. I have a page index.php, a group of pages that all start with widget-(thensomething).php and then the rest of the sites. To serve the Adsense codes I have soemthing like this in _adsenseIncludes.php:

<?php
//Adsense Includes

$ourOpenPage = $_SERVER['PHP_SELF'];

if (preg_match ("/^\/index.php/i", $ourOpenPage)) {
// Adsense code for the index page
?>

YOUR ADSENSE CODE

<?php }
elseif (preg_match ("/^\/widgets-.*/i", $ourOpenPage)) {
// Adsense for the widget-* pages
?>

YOUR ADSENSE CODE

<?php }
else {
// Adsense code for all other pages
?>

YOUR ADSENSE CODE

<?php }
?>

Note how I close and reopen the <php and?> PHP tags for each if-statement. This way you dont have to escape all the " etc in PHP but you can simply copy/paste the code exactly as Google gave you.

This code can also easily be adapted to make a single include file for example for metatags etc.

Hope this was usefull to at least one person =)

activeco

2:41 pm on Sep 6, 2005 (gmt 0)

10+ Year Member



For all those confused and others with similar questions who don't want to think much:
No need to make things complicated.
Include works just fine and there is no parsing problem.

Adsense.php:
====================================
<?php
echo '

<SCRIPT type=text/javascript><!--
google_ad_client ...
...
//--></SCRIPT>

<SCRIPT
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"
type=text/javascript>
</SCRIPT>

';
?>
======================================================

YourPage.php:
======================================================
<html><header>....
....
<body>...
....
....
<?php
include 'Adsense.php';
?>

...
...
</body></html>
======================================================

Keep it simple.

RonS

11:10 pm on Sep 7, 2005 (gmt 0)

10+ Year Member



I think this is simple:

adsense.txt:
<your adsense code exactly as provided by google>

Page.php:
echo file_get_contents("adsense.txt");

or

Page.php:
printf("%s",file_get_contents("adsense.txt"));

But maybe I'm mistaken. To each their own.

Ciao!

jaames

2:25 am on Sep 22, 2005 (gmt 0)

10+ Year Member



Will google not allow it if I simply use:

<?
include("adsense.php")
?>

The above being placed where exactly i want the adsense to be?

and in the adsense.php i copy & paste exactly what code google provided for the adsense?

Also, I'm not entirely sure, but the above method does work, right?

Nikke

9:42 pm on Sep 22, 2005 (gmt 0)

10+ Year Member



Actually Jaames, that is exactly how I do it.

There are no issues whatsover with this for me.

blue_eagle

4:29 am on Sep 23, 2005 (gmt 0)

10+ Year Member



What i do is really simple compared to other posts.

on all of my pages i have this code.

<? include("adsenseetc.htm")?>

whenever i want to change something in my adsense code i just change adsenseetc.htm file and there yea go, it changes on all pages.

Good luck!

activeco

8:36 am on Sep 25, 2005 (gmt 0)

10+ Year Member



Lol.
It's like deaf and mute talking to each other.

jaames

10:25 pm on Sep 27, 2005 (gmt 0)

10+ Year Member



with or without the php?

<?
include("adsense.php")
?>

or

<php?
include("adsense.php")
?>