mixed code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

mixed code

Post by Vegan »

been working on countermeasure against ad blockers

seems to be something wrong with mixed PHP JavaScript

Code: Select all

<script type="text/javascript">
	if (document.getElementById("tester") == undefined) {
	<?php
		function crawler() {
			// Wladimir Palant is the primary developer of the ad blocker
	   		$sites = 'Google|Yahoo|msnbot|'; // Add the rest of the search-engines 
	   		return (preg_match("/$sites/", $_SERVER['HTTP_USER_AGENT']) > 0) ? true : false;  
		}
		if (!crawler) {
			echo 'alert("An ad blocker has been detected. Please remove the program to use this site");'
			echo 'document.location.href = "http://hardcore-games.azurewebsites.net/about/ad-supported.php";'
		}
	?>
	}
</script>
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: mixed code

Post by Christopher »

Did you check the error message? If it is not displayed, then it will be in the logs. crawler is a function. It should be:

Code: Select all

		if (!crawler()) {
(#10850)
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: mixed code

Post by requinix »

Also keep in mind that if you're only using this function once then you may just as well not use a function at all.

Code: Select all

if (preg_match("/Google|Yahoo|msnbot/", $_SERVER['HTTP_USER_AGENT']) == 0) {
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: mixed code

Post by Vegan »

that function has many uses besides spotting a search engine

I have thought long and hard on how to deal with miscreants.......

I simply placed the code there where it can be easy to edit if needed

this code is in the page header so its handled long before the main document every is reached
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
Post Reply