PDA

View Full Version : Google Module


greg watson
11-04-2005, 10:19 PM
Ok ... I've followed the Adsense Tutorial to create a Google module ...

The module works fine with the first article that is viewed.

However, if you browse to a second article, the following error message is generated:

"Unable to add cookies, header already sent.
File: /..../gars/mods/google.php
Line 11"

Here is my google.php file:

<?PHP
if ($stage == "display")
{
eval('$output.="' . fetch_template('GARS_google') . '";');
}
elseif($stage == "settings")
{
print_description_row("This module will display Google Adsense");
}
?>

Here is my GARS_google template (which is just plain adsense code):

<script type="text/javascript"><!--
google_ad_client = "pub-7481905953329668";
google_ad_width = 160;
google_ad_height = 600;
google_ad_format = "160x600_as";
google_ad_type = "text";
google_ad_channel ="";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

Any suggestions?

Thanks,
Greg

James Goddard
11-05-2005, 01:38 AM
"Unable to add cookies, header already sent.
File: /..../gars/mods/google.php
Line 11"


I've never done a GARS module so I can't be of much help, however I can tell you what that error message means.

It's refering to the HTTP (not HTML) headers. What is happening is that somewhere your script is outputing data before another part of the script that is trying to modify the HTTP header.

James

The Geek
11-05-2005, 08:30 AM
huh, I cant see for the life of me how that php can output anything however I dont use Google ads so there may be something obvious im missing.

When you say first article is OK, what do you mean? ie Other articles dont work, multiple pages dont work, etc...

Does anything get output at all?

greg watson
11-05-2005, 11:32 PM
huh, I cant see for the life of me how that php can output anything however I dont use Google ads so there may be something obvious im missing.

When you say first article is OK, what do you mean? ie Other articles dont work, multiple pages dont work, etc...

Does anything get output at all?

I add it back in on Monday and send you the links so you can check it out <grin>...

But what happens is that if you open up a browser and browse to an articles forum, whatever article you view first will always work ... any other articles you try to view will generate that error message (in the image above) and be totally unviewable ...

If you go to a different computer ... and browse to the same articles forum but look at a different article ... then this article will be viewable and again, any other articles will not be ...

So it sure appears that we have a variable somewhere that is getting corrupted ...

I'll turn it back on again on Monday so you can see <grin> ...

Greg

greg watson
11-09-2005, 06:40 PM
Whatever the bug was ... its fixed in the new RC1 version ... uploaded the new update and the google module works fine ...

Greg

The Geek
11-09-2005, 06:41 PM
Whew. I was really scratching my head on that one!

greg watson
11-09-2005, 09:37 PM
Whew. I was really scratching my head on that one!
I spoke too soon ...

I've got a test board up and running that you can log into the admin panel and play to your heart's content <grin> ...

http://www.IowaBeautiful.com

Google Adsense Module is working in ShowThread ... after I uploaded the new RC1 files. However, if you now try to add the module to the ForumDisplay, the same original error is generated ...

Go into GARS | Modules | Default Set | Forum Display |

Then at the bottom, select Google Adsense as a module to add

Choose Left or Right for a section and set an order if you like ... and then click SAVE ...

You will now get an error message if you try to browse any article forum ... with the exact same error message up above ...

I'll PM you the login details to the admin panel ... this is a test board, so other than my wife and I entering content prior to launching, you can't harm this board <Grin> ...

Greg

The Geek
11-10-2005, 06:36 AM
Ill get to it tonight :)

kall
01-04-2006, 09:06 AM
Can you? I am getting this issue myself now. :(

here is a thread it happens on (http://www.nzboards.com/forums/new-zealand-news-feeds/beached-whales-shot-new-zealand-cbs-news-24308/).. Logged in in Firefox it is ok, guest on IE gets the message.

The Geek
01-04-2006, 04:20 PM
I just dont get it. It doesnt even get flushed down to the browser until the page is rendered. As James mentioned, it looks like there is output getting sent before the headers. Furthermore I cant see why it would occur in forumdisplay but not showthread.

Ill see what more I can do to test. Its hard because I dont use adsense :(

Do you know if there is some test HTML that google can provide?

kall
01-04-2006, 05:21 PM
Thing is, I'm not even using Adsense... I got banned when someone clicked my ads 1000's of times in one day.

Anyway....its basically just an advertising module calling my random ads from phpadsnew. :)

The Geek
01-04-2006, 06:22 PM
can you post the HTML? I know it wont work for me, however it should allow me to duplicate the bug (I hope!)

greg watson
01-04-2006, 11:38 PM
I just dont get it. It doesnt even get flushed down to the browser until the page is rendered. As James mentioned, it looks like there is output getting sent before the headers. Furthermore I cant see why it would occur in forumdisplay but not showthread.

Ill see what more I can do to test. Its hard because I dont use adsense :(

Do you know if there is some test HTML that google can provide?

Any HTML will work ... it does not need to be Google Adsense ... it does not need to be GAB ... any HTML will work ...

This is perfectly replicable day after day <grin> ... if you follow the steps listed in this thread you should be able to reproduce it on your own websites http://www.thevbgeek.com/showthread.php?t=719 ...

The Geek
01-05-2006, 09:56 AM
Still cant reproduce it.

See this response here-> http://www.thevbgeek.com/showpost.php?p=4482&postcount=12

blackhat
01-07-2006, 04:52 PM
I get this error also when submitting an article, when I removed the adsense code it works. Could there be the javascript that creates the error ?

The Geek
01-07-2006, 05:44 PM
no, because the javascript cant run until it gets pushed down to the client. Can you check something for me?

Delete EVERYTHING from the template and save it to see if you get the same error. I tried this on gregs setup yesterday (blank templates) and I was STILL getting the error which points to the php file.

Rich
01-20-2006, 07:40 PM
Hello,

I found a way to make it work without the errors, but it is VERY unconventional. lol I removed the closing ?> and all works. I am thinking that the application is being closed AFTER everything loads. Somewhere in the code, it HAS to be closing because the page is rendering properly.

This is my google module code:

<?PHP
if ($stage == "display")
{
eval('$output.="' . fetch_template('GARS_google') . '";');
}
elseif($stage == "settings")
{
print_description_row("This module will display Google Adsense");
}

The above removes the header images error....at least for me!

** Update **
I just tested it on showthread and forumdisplay. I also added a new article. This code works to remove the errors. NOW, I want to know why it doesn't need to close. lol Where is it closing? (It IS closing somewhere because my pages are still coming back as XHTML compliant. I would assume that the end result for a non closed tag would generate incomplete output somewhere causing errors.)

The Geek
01-24-2006, 04:41 PM
Got me, however with gregs problem, I simply uploaded the module I posted here: http://www.thevbgeek.com/showpost.php?p=4482&postcount=12

ANd it worked which made me think of a possible bad upload?

Rich
01-25-2006, 01:23 PM
Hello,

I don't know what the deal was Sam, but I was getting continual errors with the closing tag. Once I removed it, everything worked. I am running the unclosed module on my Reptile Site as well as the one I am developing now.

Both are still xhtml compliant, and the google ads are working great. :D

LBmtb
02-12-2006, 04:51 AM
Unconventional? Yes. Did it work for me (I had the problem also)? Yes!

Hmmm . . .