Page 1 of 1

mixed code

Posted: Sun Oct 27, 2013 8:13 am
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>

Re: mixed code

Posted: Sun Oct 27, 2013 6:49 pm
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()) {

Re: mixed code

Posted: Sun Oct 27, 2013 7:17 pm
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) {

Re: mixed code

Posted: Mon Oct 28, 2013 8:09 pm
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