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
Comment #2
jamesweston commentedOk 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
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
Comment #4
jamesweston commentedi 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
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.
Run it both on an http page and on a https page, please!
Comment #7
jamesweston commentedOk 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)
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
I think that checking for stripos($_SERVER['SERVER_SOFTWARE'], 'apache') !== FALSE will do the trick. I can't test it right now..
Comment #10
jamesweston commentedOk 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;
}
Remove the function_exists section completely.. The stripos replaces that as the 'Apache detection' condition.
João
Comment #12
jamesweston commentedAll 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;
}
The fix highlighted above was commited to CVS. It should be in the latest dev in a few hours.
João
Automatically closed -- issue fixed for 2 weeks with no activity.
Comment #1
jcnventuraThe way you posted your code seems to reduce the function to:
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