The following code:

function _adsense_page_match() {
  // Do not show ads on secure pages.
  // This is for two reasons:
  // Google would most probably not have indexed secure pages
  // and it also prevents warnings about mixed-content
  // Thanks to Brad Konia http://drupal.org/node/29585
  // Should be restricted when running on Apache only
  if (function_exists('apache_get_version') && isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on')) {
    return FALSE;
  }

Should be

function _adsense_page_match() {
  // Do not show ads on secure pages.
  // This is for two reasons:
  // Google would most probably not have indexed secure pages
  // and it also prevents warnings about mixed-content
  // Thanks to Brad Konia http://drupal.org/node/29585
  // Should be restricted when running on Apache only
  if (function_exists('apache_get_version') || isset($_SERVER['HTTPS']) || ($_SERVER['HTTPS'] == 'on')) {
    return FALSE;
  }

This works on my apache server

Comments

jcnventura’s picture

Status: Active » Postponed (maintainer needs more info)

The way you posted your code seems to reduce the function to:

function _adsense_page_match() {
  return FALSE;
}

on Apache servers. I run my site in Apache only, and I can tell you that I don't want _adsense_page_match() to return FALSE on all pages.
So, either something important is missing from your patch above, or you're trying to do something strange..

Actually the code as it is now seems perfectly fine to me.

João

jamesweston’s picture

Ok i missed out the rest of the function the

/**
 * Determine if AdSense has permission to be used on the current page.
 *
 * @return
 *   TRUE if can render, FALSE if not allowed.
 */
function _adsense_page_match() {
  // Do not show ads on secure pages.
  // This is for two reasons:
  // Google would most probably not have indexed secure pages
  // and it also prevents warnings about mixed-content
  // Thanks to Brad Konia http://drupal.org/node/29585
  // Should be restricted when running on Apache only
  if (function_exists('apache_get_version') || isset($_SERVER['HTTPS']) || ($_SERVER['HTTPS'] == 'on')) {
    return FALSE;
  }

  $pages = variable_get('adsense_access_pages', ADSENSE_ACCESS_PAGES_DEFAULT);
  $visibility = variable_get('adsense_visibility', ADSENSE_VISIBILITY_DEFAULT);

  if ($pages) {
    if ($visibility == 2) {
      return drupal_eval($pages);
    }
    $path = drupal_get_path_alias($_GET['q']);
    $page_match = drupal_match_path($path, $pages);
    if ($path != $_GET['q']) {
      $page_match = $page_match || drupal_match_path($_GET['q'], $pages);
    }

    return !($visibility xor $page_match);
  }
  else {
    return !$visibility;
  }
}

All that is changed is this if statement

  if (function_exists('apache_get_version') || isset($_SERVER['HTTPS']) || ($_SERVER['HTTPS'] == 'on')) {
    return FALSE;
  }

So the the module doesn't show ads on HTTPS pages i don't not if this break computability with IIS

jcnventura’s picture

Status: Postponed (maintainer needs more info) » Needs work

Really, look at your code.. You have something like:

if (something that is always true in Apache || whatever || whatever) {
return FALSE;
}

On apache servers, that function always returns false.. It's as simple as that.. So on apache servers, you've basically disabled the module. And I mean really disabled, no ads on https pages, but also no ads on http pages, no ads at all. Well done, but there are easier ways to disable it without changing the code.

João

jamesweston’s picture

i understand what you are saying about the if statement but its results work on my site i can see ads on http://meamod.com but not on https://meamod.com/user so its working

jcnventura’s picture

Status: Needs work » Postponed (maintainer needs more info)

Can you help then?

Please insert the following lines into just before the if:

var_dump(function_exists('apache_get_version'));
var_dump(isset($_SERVER['HTTPS']));
var_dump($_SERVER['HTTPS']);

Do a refresh and tell me what it prints out for you. Then delete the code.

jcnventura’s picture

Run it both on an http page and on a https page, please!

jamesweston’s picture

Ok this is the output

HTTP Page
bool(false) bool(false) NULL bool(false) bool(false) NULL

HTTPS Page
bool(false) bool(true) string(2) "on"

I am running Apache/2.-.-- (Unix)

jcnventura’s picture

Status: Postponed (maintainer needs more info) » Needs work

Haha!

Found the guilty party.. Apparently, in some strange cases, it's possible to be running Apache, but apache_get_version() is not defined (according to the documentation it's only available with the filter API in Apache 2).

So, your code works because it's still false in the http case, and it's true in https.. For the rest of us who have the filter API, it fails horribly.. I'll try to come up with a better solution.

João

jcnventura’s picture

I think that checking for stripos($_SERVER['SERVER_SOFTWARE'], 'apache') !== FALSE will do the trick. I can't test it right now..

jamesweston’s picture

Status: Needs work » Postponed (maintainer needs more info)

Ok so this seems to be working for me

  if ((function_exists('apache_get_version') || stripos($_SERVER['SERVER_SOFTWARE'], 'apache') !== FALSE) && isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on')) {
    return FALSE;
  }
jcnventura’s picture

Remove the function_exists section completely.. The stripos replaces that as the 'Apache detection' condition.

João

jamesweston’s picture

All done and works I just left it in because there was a bug what SERVER_SOFTWARE would return but it is really not applicable in this situation

  if (stripos($_SERVER['SERVER_SOFTWARE'], 'apache') !== FALSE && isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on')) {
    return FALSE;
  }
jcnventura’s picture

Status: Postponed (maintainer needs more info) » Fixed

The fix highlighted above was commited to CVS. It should be in the latest dev in a few hours.

João

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.