|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
bimal Smarty Elite
Joined: 19 Apr 2007 Posts: 423
|
Posted: Thu Apr 15, 2010 8:22 pm Post subject: Blocking the ad-servers on your local computer |
|
|
If you are building your application with a feature to show third party ads on your site, you may find this interesting to read out.
On your production website, you have to show the ads, while on your localhost, you should not. Normally, the ads provider, like google ads count against your account, they find you to misuse the ads-scripts. So, it is a wise idea NOT to use those scripts on your localhost. But the same smarty template, without modification, should display ads on the real server.
There are several tricks to solve this. And, I am showing two ideas here:
The server plugin, download it at here, and save it into your plugins directory. The basic code seems like:
Code: | /**
* Determines the real server, without the $_SERVER['SERVER_NAME'];
*/
function smarty_modifier_server($time=0)
{
$server = ($_SERVER['SERVER_ADDR']!=$_SERVER['REMOTE_ADDR']);
return($server);
}
|
Explanation: On a local server, the server's ip address and client's ip address will be same. So, this is how to use this plugin:
Code: | {if ''|server}
...Your ad-scripts...
{/if} |
The other way is to use your hosts file. On windows, it is normally at:
C:\WINDOWS\system32\drivers\etc\hosts
Open this file with notepad, and add IP address of your ad server as your own. For example:
Code: | # Disable ads server
127.0.0.1 pagead2.googlesyndication.com
127.0.0.1 resources.infolinks.com
127.0.0.1 www.google-analytics.com
127.0.0.1 ssl.google-analytics.com |
This permanently blocks those ad servers, and your computer will never reach the real ad site.
Now, you can reload your pages with ad-scripts as many times as you want! But, your real website will be able to able to serve the ads to computers other than yours. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|