Forum Moderators: open

Message Too Old, No Replies

Script to prevent Adsense on my secure pages

         

camaroboy

6:46 pm on Jul 13, 2007 (gmt 0)

10+ Year Member



I am trying to run Google Adsense on my website. This is an ecommerce website and has both secure and unsecure pages. Does anyone know a script or code I can use to disable Adsense from showing on my secure (https) pages?

I found some script on another forum when I was searching for how to do this. The script is as follows:

{if $current_location == $http_location}
Google AdSense Goes Here
{/if}

The problem is I cannot get that to work with Adsense because the Adsense code itself has 2 different javascript codes in it.

Will the above script work? Am I just putting it in wrong? Or do I need a different script all together?

penders

8:53 pm on Jul 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I think the idea behind your script is OK, but it looks incomplete/pseudo code? What are the curly brackets {..} for? $current_location and $http_location are variables, but what are their values? What language is it... JavaScript, PHP? Too many Q's...

I would have thought that the preferred method would be to do this server-side with PHP or similar, that way completely eliminating the Google code from your secure pages. If using JS, then the code will still be there, just not executed.

In PHP I would have thought you could examine the contents of $_SERVER["HTTPS"] (the exact value depends on IIS / Apache)

However, since this is the JS Forum, may be you can examine location.href to see if "http:" is at the start of the URL ...?


if (location.href.indexOf('http:') == 0) {
//Google AdSense Goes Here
}

rocknbil

9:17 pm on Jul 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would have thought that the preferred method would be to do this server-side with PHP or similar, that way completely eliminating the Google code from your secure pages.

Agreed, or if by "two javascript codes" you mean the secure version or the non-secure version of adSense, you can continue running adSense on the secure pages by pointing to the secure version (but it will slow it down even more.) You can use the HTTPS environment variable on linux:

if (! $ENV{'HTTPS'} or ($ENV{'HTTPS'} =~ /off/i)) {
## adSense code
}
else {
## secure adSense code OR eliminate this else completely
}

camaroboy

3:24 pm on Jul 16, 2007 (gmt 0)

10+ Year Member



Unfortunatly becuase this is an ecommerce company they do not allow me to do any php because of the customer information stored on the servers. This is why I believe that javascript is my only option.

camaroboy

3:45 pm on Jul 16, 2007 (gmt 0)

10+ Year Member



penders,

It looks like the code you gave me does work as far as not showing the ad on a secure page. I am still getting the "secure and unsecure items" pop up box though because the Adsense code is trying to get the unsecure Google link:

src="http://pagead2.googlesyndication.com/pagead/show_ads.js"

What do I need to do in this case?

Drag_Racer

5:04 am on Jul 17, 2007 (gmt 0)

10+ Year Member




<div id="adsensediv">
-- adsense code here --
</div>
<script type="text/javascript">
var url = window.location.href.split("/");
if(url && url[0].toLowerCase() == 'https:'){
document.getElementById('adsensediv').innerHTML = '';
}
</script>

I don't know if this will get rid of the security warning though...

penders

12:40 pm on Jul 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I am still getting the "secure and unsecure items" pop up box though because the Adsense code is trying to get the unsecure Google link:

Is this in the HEAD section? May be you can apply the same IF() principle, but have a document.write('<script src=".../show_ads.js" type="text/javascript"></script>') ....? Hhhmm, would that work?!