Forum Moderators: coopster

Message Too Old, No Replies

Inserting Adsense code in a PHP file

HELP! with code

         

dezertdiva

6:40 pm on Jul 29, 2007 (gmt 0)

10+ Year Member



I feel pretty stupid having to ask this and the last time I asked a question, which was about my OScommerce it cost me a couple of hundred dollars! Well worth it, but hurt the pocket. See I am a small time nobody who hasn't had but a few sales in the last year and, with only one of those on my new OScommerce site.
Anyway I am trying to figure out how to get the code I have received from Googles Adsence onto my site and cannot figure out how to. Some how in my looking for help I ended up here, so I sure hope there is someone who can tell me where to stick it (hey, not that way) I mean into which files, or file i.e., includes, and about where should it be pasted, about what line? And I am sorry I have no money to offer anyone either so I just hope someone who doesn't need the money and just likes to help out and who knows something about these .php files can find it in their heart to help me out. Maybe someday when I get smart enough about this stuff I can help someone else out.

netchicken1

7:25 pm on Jul 29, 2007 (gmt 0)

10+ Year Member



I use a php based messageabord and in the code I addad a variable and gave it the google code

Then I just put $googlebottom in the place I wanted the bottom advert and it works.

Don't forget to backslash every " you find in the code like \"

$googlebottom=("

<script type=\"text/javascript\"><!--
google_ad_client = \"**********";
google_ad_width = 336;
google_ad_height = 280;
google_ad_format = \"336x280_as\";
google_ad_type = \"text_image\";
google_ad_channel = \"*****************\";
google_color_border = \"FAFAF6\";
google_color_bg = \"FAFAF6\";
google_color_link = \"008486\";
google_color_url = \"008000\";
google_color_text = \"000000\";
//--></script>
<script type=\"text/javascript\"
src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">
</script>

");

HarryM

8:50 pm on Jul 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you don't want to mess around modifying Google script you can do this.

$googlescript = <<< eof
<script type="text/javascript"><!--
google_ad_client = "**********";
google_ad_width = 336;
google_ad_height = 280;
google_ad_format = \"336x280_as\";
google_ad_type = "text_image";
google_ad_channel = "*****************";
google_color_border = "FAFAF6";
google_color_bg = "FAFAF6";
google_color_link = "008486";
google_color_url = "008000";
google_color_text = "000000";
//--></script>
<script type=\"text/javascript\"
src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">
</script>
eof;

If you want to put the script in some other PHP variable you can do this:

$content = "blah blah blah {$googlescript} blah blah";

Or if you want to put the script in the HTML you can use:

<?php print $googlescript;?>

Or you can save the Google script in a text file as an include called (say) google.inc. Then call it from within your HTML by:

<?php require ("domain.com/directory/google.inc");

LBmtb

11:51 pm on Jul 29, 2007 (gmt 0)

10+ Year Member



I would suggest using single quotes versus double quotes as mr chicken suggested. That way you don't have to escape all the double quotes.

Another option would be to do would be this:

<?php
print $header;
print $content;
// print whatever

if ($showAdsense)
{
// ohnoes, here comes the google code
?>
<script type="text/javascript"><!--
google_ad_client = "**********";
google_ad_width = 336;
google_ad_height = 280;
google_ad_format = \"336x280_as\";
google_ad_type = "text_image";
google_ad_channel = "*****************";
google_color_border = "FAFAF6";
google_color_bg = "FAFAF6";
google_color_link = "008486";
google_color_url = "008000";
google_color_text = "000000";
//--></script>
<script type=\"text/javascript\"
src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">
</script>
<?php
}
// now we continue with PHP
?>

HarryM

12:14 pm on Jul 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I use include files because I find they give me flexiblity and ease of maintenance. I have includes for each channel in various formats, eg., banner, large rectangle, link, etc. I then set php variables for each page group to include the ones required.

There are many ways of adding Google's script. It depends on how you are using PHP in your site.

[edited by: HarryM at 12:16 pm (utc) on July 30, 2007]

dezertdiva

6:00 pm on Jul 30, 2007 (gmt 0)

10+ Year Member



WOW Thanks to all of you! Of course half of it all went over my head, so I guess its a good thing I am short or I would have gotten a headache from all the info. Great stuff. But I have to say that I am soooooooooo new to this that I don't know what file to insert code, and/or is this sdsence code a stand alone file that you copy to a html editor and save as a php file then upload to the includes folder? Did that make any sense at all or does it just tell you how unknowing I really am?
And how does one aquire an HTML/PHP editor? My installer has know idea about them.
Monica

[edited by: jatar_k at 7:48 pm (utc) on July 30, 2007]
[edit reason] no urls thanks [/edit]

coopster

1:02 am on Aug 8, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Hi dezertdiva (Monica) and welcome to WebmasterWorld.

There are plenty of open source editors out there as well as WYSIWYG editors to help you get started. Also, have a look at the PHP Forum Library [webmasterworld.com] on tips to get started using PHP [webmasterworld.com].