PDA

View Full Version : including external php file not working?


Geraldm
08-06-2008, 10:03 AM
Hi,

I'm trying to get asrep working with vbulletin. Basically, under the first post in a thread I display a Google Adsense Ad.

I want to be able to use the asrep fraud prevention feature. So I have done the following.

Created an external php file called displayad1.php in the root of my forum with the following content:
<?php
require_once "asrep/fraudprev.php" ;
# show only if the visitor have seen less than 10 ad displaying pages
# and clicked 2 times or less in the last 1 hour
if(asrep_ipStatsOK(NULL, 0, 1*60*60)){
?>
<script type="text/javascript"><!--
google_ad_client = "<my pubid>";
google_ad_slot = "5185614664";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<?php }else{ ?>
nothing to display
<?php } ?>


Then I create a new plugin which hooks into showthread_start:


<!-- AdSense Code -->
ob_start();
require(DIR . '/displayad1.php');
$displayad1 = ob_get_contents();
ob_end_clean();


At this point I have not added $displayad1 to my template, but if I visit my forum I get the following error message:


Parse error: syntax error, unexpected '<' in /path/to/public_html/forums/showthread.php(102) : eval()'d code on line 1

Can someone please tell me what I am doing wrong?

Marco van Herwaarden
08-06-2008, 10:20 AM
You can not use HTML style comment in PHP/Plugins. ;)

<!-- AdSense Code -->Is HTML, not valid in a PHP script.

Geraldm
08-06-2008, 10:25 AM
Ah, yes, thank you for that, I have removed that line and it works.. But I have come across another problem......

I've add the $displayad1 to the postbit template.

If I hook the plugin to the showthread_start location, no ads are displayed, but it I change the location to postbit_display_start the ad is displayed as per normal.

Is postbit_display_start called for all posts in a thread? if so how can I get the plugin to only run once when displaying posts in a trread? As stated above, i've tried adding it to the showthread_start location, but no ads are displayed?

Cheers ...
Gerald.

Marco van Herwaarden
08-06-2008, 11:00 AM
Try the showthread_complete hook location.

Geraldm
08-06-2008, 12:15 PM
Hi,

Changing it to the showthread_complete hook location doesn't work, no ads are displayed. Any other suggestions?

Opserty
08-06-2008, 12:32 PM
Use $GLOBALS[displayad1] in the template.

Marco forgot about his variable scopes. Rookie... :p

Geraldm
08-06-2008, 02:01 PM
Hi,

I had to change the hook location to showthread_start and now $GLOBALS[displayad1] works perfectly.

Thanks everyone for their help! :)