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 |
Jump to:
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
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
#3
#4
#5
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
Fixed in CVS commit 47501.
#7