Some sites seem to customize their pages depending upon where they detect you are from (i.e. - U.S., Canada, UK, France, etc.).

How do they do that?

It would be nice to do something similar. My site is pretty simple, but I would like to avoid the risk of having a family member click on my AdSense ads and getting me kicked out of the program. So now I am wondering if there is some way to have a non-ad page served to my IP address, and a page with the ad on it served to everybody else. How would I go about doing this?

Dani AI

Generated

A concise primer on options, tradeoffs, and safe practices for IP- or location-dependent pages, drawn from ’s scenario and ’s server-side approach.

Server-side flag (recommended for "no‑ads" for known users)

  • Use a small authenticated/no‑ads flag or a persistent cookie to serve a different template that omits all ad HTML and ad scripts. Not loading the ad script at all avoids accidental impressions or clicks that can look like invalid activity.
  • Do not rely on hiding ads with CSS after the ad code runs; that can still generate impressions or requests.
  • Maintain a simple admin page to toggle the flag for a household device. This is far more robust than matching a single IP.

IP-based or geo-based targeting (useful for locale differences)

  • For country/language variants, use a maintained GeoIP database or a reputable IP lookup API and cache results. Local DBs avoid per-request network calls and improve performance.
  • Remember edge cases: dynamic home IPs, carrier NAT, mobile networks, IPv6, and CDNs/proxies. When behind a proxy or CDN, read the correct forwarded header to get the true client address.
  • As an alternative signal, consider Accept-Language as a lightweight hint for language-only customizations.

Testing, privacy, and policy notes

  • For development or QA, run pages with test ads or a local/dev mode rather than using live ad code. This prevents accidental invalid clicks while checking layout.
  • IPs are personal data in many jurisdictions; record/use them only as necessary and reflect that in privacy documentation.
  • Never click own ads or request others to click them. If uncertain about policy or suspicious activity, consult the ad network support channels.

Quick checklist

  • Prefer an auth/cookie flag to exclude ads for family.
  • If using IP/Geo, use a reliable service and cache results; handle proxies and IPv6.
  • Ensure ad JS is not injected for excluded users.
  • Use test ads or dev mode when verifying placements; update privacy policy as needed.

Recommended Answers

All 2 Replies

In php $_server is the ip address of the user

<?php if(!$_server['remote_addr'] ='myip'){ echo "my adwords code"; } else { echo '<img src="filler.jpg" alt="">'; } ?>

in other languages there is similar code

Thank-you.

That looks simple enough.

I was afraid I might have to play with settings on the server and possibly mess things up.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.