[ Google-related ]
myIP() Cross Your Fingers Click Happens Google Gadgets SE Spam Google Data Centers

ajax-myIP()

an AJAX Javascript method to get the IP address

[ My IP address is 38.107.179.239 ]
This was an early attempt at creating an AJAX technique for setting google_adtest='on'; based on IP address values.
It is now obsolete and kept here only for reference purposes.

Please the current version of myIP instead.

<script type="text/javascript"><!--
if( myIP() ) google_adtest='on';
google_ad_client = "pub-0000000000000000";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
google_ad_channel ="2380527166";
google_color_border = "EFEFEF";
google_color_bg = "EFEFEF";
google_color_link = "0000FF";
google_color_url = "0000FF";
google_color_text = "000000";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

Most of the AJAX examples found in the wild are asynchronous or non-blocking but these would not fit this case as we need the reply back from the server (is it my IP?) before the page is finished loading. Many examples mention synchronous requests in passing but there are a few extra details to consider, particularly with regard to Netscape.

example-myIP.js

myIP client Javascript

The server portion is extremely simple as all it has to do is echo the IP address. It does need to reside in the current directory as perceived by the script to avoid triggering a permission elevation request.

get_ip_address.php

myIP php server script
<?php echo $_SERVER["REMOTE_ADDR"]; ?>

So to pull it all together and implement myIP() there are just a few things to be done:

  1. put a copy of get_ip_address.php in the current directory
  2. put a copy of example-myIP.js in the current directory as ip.js then edit so it is set with your own IP address(es) Or optionally, you can also pass a single address or a comma-delimited list of addresses as an argument to the function like this  myIP('127.0.0.*,10.1.1.1'); 
  3. load the client javascript. I like to do it this way:

    <script language="javascript" src="ip.js"></script>

  4. Add the call to the myIP function in your AdSense scripts right before the publisher ID.

    <script type="text/javascript"><!--
    if( myIP() ) google_adtest='on';
    // to prove to yourself it is actually working
    // uncomment the next line
    // if( google_adtest='on' ) alert('google_adtest=on');
    google_ad_client = "pub-0000000000000000";
    ...

If you have installed it, set it up correctly with your IP address and you have the left the variable bShowBorder set to its default value of 'true' then you should see a distinctive yellow border around your ads something like the sample on the left whenever you are looking at your own pages from one of your own IP's ... so if you see the border you can relax because if you accidentally click on one of your own ads now, it's no big deal.

Google Pack contains 13 of the world's best programs. Install just one of them or all of them for free





DISCLAIMER: The information on this site is provided as is. The author(s) make no claim as to its correctness or fitness for any purpose. This website is not affiliated with or approved by Google. In fact every time they see it, Larry Page and Sergey Brin just shake their heads in kind of a sad way and wonder what this world is coming to.


© 2012 Michael Thompson