ajax-myIP()
|
an AJAX Javascript method to get the IP address
|
[ My IP address is
38.103.63.60 ]
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.
|
<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.phpmyIP 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:
- put a copy of get_ip_address.php in the current directory
- 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');
- load the client javascript. I like to do it this way:
<script language="javascript" src="ip.js"></script>
- 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
|