Welcome to WebmasterWorld Guest from 54.159.50.111

Forum Moderators: incrediBILL & martinibuster

Message Too Old, No Replies

adsense in php code

dont know why its happening!

     
10:27 pm on Feb 19, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:Jan 4, 2006
posts:431
votes: 0


I'm creating a new site..and i was designing the layout of the site and where to put the ads and stuff when i ran into a lil problem. When I put the adsense code into one of my tables and then refresh the page to see how it looks, it makes the page blank, nothing shows up. if i put regular text in that table it shows up with the text but as soon as i put the adsense script the page loads as a blank...why?
3:45 am on Feb 20, 2006 (gmt 0)

Junior Member

5+ Year Member

joined:Feb 19, 2006
posts:43
votes: 0


I used to experience this too. Maybe adsense does not like (<? php) syntax.

I will appreciate any workaround this.

3:49 am on Feb 20, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Jan 24, 2006
posts:310
votes: 0


Does your script have error_reporting turned off? Sounds like you are getting an error and the script is dying but not returning any reason why.

I use Adsense in PHP all the time.

1:36 pm on Feb 20, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Feb 10, 2004
posts:263
votes: 0


Same here, so just assume you have made a silly mistake!
2:15 pm on Feb 20, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 19, 2003
posts:398
votes: 0


Try putting your ad code in 'ad.php' and then including it in your main page.

<?PHP include "ad.php";?>

That's if you aren't already doing something like this of course. This method is also a lot more dynamic than simply pasting your code on every single page of the site.

W.

2:52 pm on Feb 20, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Jan 24, 2006
posts:310
votes: 0


Try putting your ad code in 'ad.php' and then including it in your main page.

This is the best way to do it for sure. When a time comes when you want to change the layout of the ad, you only have to edit one file instead of multiple ones.

4:13 pm on Feb 20, 2006 (gmt 0)

New User

10+ Year Member

joined:Jan 5, 2004
posts:31
votes: 0


Hi,

This page appears blank when there error in php code.

If you are using it like <?php

echo"

<script type="text/javascript"><!--
google_ad_client = "#*$!";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
google_ad_channel ="";
google_color_border = "E7C794";
google_color_bg = "E7C794";
google_color_link = "000000";
google_color_url = "FFFFFF";
google_color_text = "993300";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

";

put in "\" back slash everywhere in php code.

dont put back slashes for echo tags.

wrong way

<?php

echo "

<script type="text/javascript"><!--

";
?>

correct way

<?php

echo "

<script type=\"text/javascript\"><!--

";
?>

just notice the back slashes.

4:15 pm on Feb 20, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:Jan 4, 2006
posts:431
votes: 0


thanks taran..that worked!
4:35 pm on Feb 20, 2006 (gmt 0)

New User

10+ Year Member

joined:Jan 5, 2004
posts:31
votes: 0


you are welcome.

actually the same thing happened to me few years ago when I moved from html to php.

there's lots more to learn for you.

4:47 pm on Feb 20, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Jan 24, 2006
posts:310
votes: 0


Honestly, it is just easier to do this:


some php code here;
?>
PUT ADSENSE CODE HERE
<?php
Resume php code here;

end;
?>

The nice thing about PHP is that you can include HTML and code on the same page, just close the <?php tag, enter your HTML, and then open it back up. You can do this inside of a loop, while, foreach, if, etc., blocks. For example:


<?php
foreach ($items as $item) {
?>

I have an item, and it's name is <?php echo $item;?>

<?php
}
?>

9:57 pm on Feb 20, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:Jan 4, 2006
posts:431
votes: 0


Taran,
Instead of putting \ in all of my codes can i just do it in the adsense code. it seems it's easier...would that be considered messing with the code and is that against the TOS.
10:02 pm on Feb 20, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Dec 1, 2003
posts:311
votes: 0


Intead of puting \ before every double-quote ". Just start and en your php string using single quotes. Like:

$string = 'this displays a double quote here " and again here ". now, I am closing the string';

insted of :

$string = "this displays a double quote here \" and again here \". now, I am closing the string";

Both of them work, but the first one was opened-closed using single quote, so, no need to put \ before the double quotes.

10:05 pm on Feb 20, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Aug 24, 2005
posts:121
votes: 0


Easier still is:

echo <<<END
put anything you like here, dont need to escape any """" invalid characters or the like.
END;

Or if you are just including a file, dont have to worry about escaping any of the chars, just use

include_once('your_ad_file.ext');
3:13 pm on Feb 21, 2006 (gmt 0)

New User

10+ Year Member

joined:Jan 5, 2004
posts:31
votes: 0


Taran,
Instead of putting \ in all of my codes can i just do it in the adsense code. it seems it's easier...would that be considered messing with the code and is that against the TOS.

..

No the actual output of the echo command will not include back slashes.