Prevent AdSense Module from displaying ads on secure pages

bkonia - August 24, 2005 - 20:59
Project:AdSense
Version:4.6.x-1.x-dev
Component:Code
Category:task
Priority:normal
Assigned:kbahey
Status:closed
Description

This is a modified version of the _adsense_page_match() function, which prevents the AdSense Module from displaying ads on secure pages. The AdSense external Javascript code is served from a non-secure server; Google does not offer a secure (https) version of the Javascript. Therefore, if you display AdSense ads on secure pages, your visitors will get "Mixed Content" warnings in their web browsers. This is highly undesirable and unprofessional, hence the reason for this patch.

Simply replace the existing _adsense_page_match() function with the code below:

/**
* 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() {
  $page_match = FALSE;
  $visibility = (int)variable_get('adsense_visibility', '0');
  $pages = variable_get('adsense_access_pages', '');
 
  if ($pages) {
    // Specific pages are configured
    $path = drupal_get_path_alias($_GET['q']);
    $regexp = '/^('. preg_replace(
      array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'),
      array('|', '.*', '\1'. variable_get('site_frontpage', 'node') .'\2'),
      preg_quote($pages, '/')) .')$/';
    $page_match = !($visibility xor preg_match($regexp, $path));   
  }
  else {
    // No pages are configured
    if ($visibility === 0) {
      // We are set to "Show on every pages except..."
      $page_match = TRUE;
    }
  }
  // Do not show ads on secure pages (prevents mixed-content warnings)
  if (isset($_SERVER['HTTPS'])) {
    $page_match = FALSE;
  }
  return $page_match;
}

#1

kbahey - August 24, 2005 - 22:58
Assigned to:Anonymous» kbahey
Status:needs review» fixed

This is a good idea.

Also, most probably Google did not index the secure pages, and hence the ads would not be targeted.

Fix committed.

#2

Anonymous - September 8, 2005 - 06:54

#3

Anonymous - September 22, 2005 - 07:01

#4

Anonymous - October 6, 2005 - 07:20
Status:fixed» closed

#5

NITEMAN - December 6, 2005 - 18:50
Version:<none>» 4.6.x-1.x-dev
Status:closed» active

I've downloaded the last revision of the module and i'm having a little throuble since my site not use https but my $_SERVER['HTTPS'] is set (it's set to off, but it's set).

I've workarounded the problem, but i think you should notice of it ;)

My server system is: Windows 2003 - MySQL 5 - Php 5.0.3 - Drupal 4.6.3
Thanks for your atenttion and i'm sorry about my english.

#6

Darren Oh - December 8, 2006 - 17:08
Status:active» fixed

Fixed in CVS commit 47501.

#7

Anonymous - December 22, 2006 - 17:15
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.