<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Web Development Blog &#187; IP address</title>
	<atom:link href="http://www.web-development-blog.com/archives/tag/ip-address/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.web-development-blog.com</link>
	<description>Web development tutorials, SEO articles and PHP script resources</description>
	<lastBuildDate>Sun, 25 Jul 2010 14:38:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Count clicks the right way!</title>
		<link>http://www.web-development-blog.com/archives/count-clicks-the-right-way/</link>
		<comments>http://www.web-development-blog.com/archives/count-clicks-the-right-way/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 21:24:06 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[PHP scripts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[click fraud]]></category>
		<category><![CDATA[clicks]]></category>
		<category><![CDATA[counter]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[IP address]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/?p=236</guid>
		<description><![CDATA[If you own a link list or directory where the listings are ranked (on some page) on the number of outgoing hits, you&#8217;re possible victim of click fraud. There are not only people clicking their own listings many times, ther eare also click bots (remote scripts) which drive the click count &#8220;into the sky&#8221; in [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><p>If you own a link list or directory where the listings are ranked (on some page) on the number of outgoing hits, you&#8217;re possible victim of click fraud. There are not only people clicking their own listings many times, ther eare also click bots (remote scripts) which drive the click count &#8220;into the sky&#8221; in a relative short time.</p>
<p>Click fraud is bad for your sites reputation and is not fair to the listings from other websites. In this PHP code show case we will explain what a webmaster need to do to get his <a href="http://www.finalwebsites.com/snippets.php?id=34">click counter</a> visitor friendly and safe.</p>
<blockquote><p>First of all don&#8217;t worry about if a click doesn&#8217;t get counted!</p></blockquote>
<h3>Objectives and requirements</h3>
<p>We need to use a link which is informative for the visitor, a link like <strong><code>http://www.domain.com/click.php?id=234</code></strong> doesn&#8217;t show the visitor the target link. better would be <strong><code>http://www.domain.com/browse.php?url=www.external-site.com</code></strong></p>
<p>We need to identify our visitor, that a click is not counted twice because the visitor click a link twice or more. We store the IP address from the visitor together with a link ID in a database.</p>
<p>We need to protect us against click bots: Many click bots are very smart, they use many IP addresses from different subnets that they look like real people. Some of them even pre-load the website to get the sites referrer information. Since we store the IP address, the click bot can&#8217;t be very effective for the fraudulent listing. Check your click results frequently and check outstanding results (if a regular listing gets normally 10 clicks a day and on some days there are many hundreds, then some one has tried hack your click system).<span id="more-236"></span></p>
<p>You need two database tables, one for the links and one for the clicks. The first one need only an ID and a column for the URL. The table for the clicks needs a column for the URL id, one for the IP address and one for the timestamp:</p>
<p><code>CREATE TABLE `links` ( `ident` INT NOT NULL, `url` VARCHAR( 100 ) NOT NULL , INDEX ( `ident` ) , UNIQUE ( `url` ) ) ENGINE = MYISAM ;</code></p>
<p><code>CREATE TABLE `clicks` ( `site_id` int(11) NOT NULL, `click_time` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,  `ip_adr` varchar(30) NOT NULL,  KEY `site_id` (`site_id`) ) ENGINE=MyISAM;</code></p>
<p>After we created the database tables we need to enter a few links, use a clean way to insert your links. Don&#8217;t use the protocol in the beginning (if you need this, store protocol in a extra table column)</p>
<p>At the moment some one has clicked the link our redirect script is executed (don&#8217;t forget the PHP tags and the building a database connection):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.yoursite.com/'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">get_magic_quotes_gpc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$gURL</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT ident FROM links WHERE ident = '&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$gURL</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://'</span><span style="color: #339933;">.</span><span style="color: #000088;">$gURL</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ident'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$IP</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$time_diff</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3600</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">24</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">14</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// count ones in 14 days</span>
		<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT COUNT(*) AS testval FROM clicks WHERE ip_adr = '<span style="color: #009933; font-weight: bold;">%s</span>' AND click_time+<span style="color: #009933; font-weight: bold;">%d</span> &amp;gt; NOW() AND site_id = <span style="color: #009933; font-weight: bold;">%d</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$IP</span><span style="color: #339933;">,</span> <span style="color: #000088;">$time_diff</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$res</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$test</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$res</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'testval'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tell</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO clicks SET ip_adr = '<span style="color: #009933; font-weight: bold;">%s</span>', site_id = <span style="color: #009933; font-weight: bold;">%d</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$IP</span><span style="color: #339933;">,</span> <span style="color: #000088;">$gURL</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.yoursite.com/'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Location: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">exit</span><span style="color: #339933;">;</span></pre></div></div>

<p>First we test if the variable URL exists and check also if there is a records for that URL. I the record exists, we test if there is a click records for the user with from the collected IP address. I the result is empty we add a new click record to our database. If the link is valid the user get redirected to the URL he already clicked, otherwise the visitor gets back to the site homepage.</p>
<p>There are a lot of free or paid scripts with a bad click counting mechanism. Use this snippet to protect your site for click fraud! In most of the cases you need only to add the click database table and you need to modify the SQL data for the links. That&#8217;s all!<strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/limit-the-number-of-downloads-per-client/" rel="bookmark" title="May 5, 2007">Limit the number of downloads per client</a></li>
<li><a href="http://www.web-development-blog.com/archives/more-advanced-features-in-phpmyadmin/" rel="bookmark" title="May 12, 2008">More advanced features in phpMyAdmin</a></li>
<li><a href="http://www.web-development-blog.com/archives/some-nice-google-adsense-updates/" rel="bookmark" title="December 13, 2007">Some nice Google Adsense updates</a></li>
</ul>
<p><!-- Similar Posts took 3.438 ms --></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/count-clicks-the-right-way/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Some support/help for Akismet</title>
		<link>http://www.web-development-blog.com/archives/some-supporthelp-for-akismet/</link>
		<comments>http://www.web-development-blog.com/archives/some-supporthelp-for-akismet/#comments</comments>
		<pubDate>Fri, 18 May 2007 08:38:59 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[PHP scripts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[akismet]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[IP address]]></category>
		<category><![CDATA[spam]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/archives/some-supporthelp-for-akismet/</guid>
		<description><![CDATA[I think the best WordPress Plugin is Akismet, without this useful tool every WP blog owner need to review all comments to select the good comments. There is a lot of work to do for this weblog, more then 100 &#8220;spammy&#8221; comments a day, and strange enough most of them are coming via the same [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><p>I think the best WordPress Plugin is Akismet, without this useful tool every WP blog owner need to review all comments to select the good comments. There is a lot of work to do for this weblog, more then 100 &#8220;spammy&#8221; comments a day, and strange enough most of them are coming via the same IP addresses.</p>
<blockquote><p>Thanks Akismet, you&#8217;re doing a really good job!</p></blockquote>
<p>Ok, next action was to block these IP addresses via .htaccess, but this doesn&#8217;t work for me. I guess the reason is that most of the spam is send via the trackback URL and it looks like that .htaccess will not work (at least on the server where this blog is hosted, regular access blocking via .htaccess works fine). Maybe these spammer connect the trackback URL via a proxy?</p>
<p>I didn&#8217;t like that some comments from our blog readers become trashed because of the big amount of spam on the internet, so I checked once a week &gt;1000 spam messages. But enough is enough, there is a way to block this guys which posting spam via the trackback URL without disabling this important feature. Just add this code to your wp-config.php file:<span id="more-97"></span></p>
<p><code>$blocked_ips = array("82.146.53.67", "72.232.173.170", "209.200.238.182", "64.111.117.7", "67.159.5.246", "82.146.53.67");<br />
if (in_array($_SERVER['REMOTE_ADDR'], $blocked_ips)) {<br />
header('HTTP/1.0 404 Not Found');<br />
exit;<br />
}</code></p>
<p>The array $blocked_ips is the &#8220;container&#8221; of all IP addresses where spam was caught by Akismet or a not recognized comment has reached your Inbox. After every repeating spam attack from one IP address you should at the IP address to this array.</p>
<p>Very useful for people with several weblogs is to host one file which holds all IP addresses from the spam posts from all your blog(s). Just replace the array declaration with this code:</p>
<p><code><br />
$blocked_ips = array_map('rtrim', file('http://your.host.com/all_ip_addresses.txt'));<br />
// changed the regular file command to remove the line ends from the array<br />
</code></p>
<p>Of course this is very time intensive but very effective, btw. the owner of each IP address is also blocked to access your website. I found this list of IP addresses from <a href="http://www.outsmartsoftware.com/fighting-spam/spam-lists/wordpress-spammer-ip-list.html">WordPress Spammers</a> and have also a look on this <a href="http://www.thetopsites.net/referer_spam/">project</a>.<strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/e-mail-links-protective-solutions-against-spam/" rel="bookmark" title="February 15, 2010">E-mail links, protective solutions against SPAM</a></li>
<li><a href="http://www.web-development-blog.com/archives/new-support-forum-for-finalwebsitescom/" rel="bookmark" title="December 31, 2007">New Support forum for finalwebsites.com</a></li>
<li><a href="http://www.web-development-blog.com/archives/how-to-choose-a-wordpress-hosting-provider/" rel="bookmark" title="January 24, 2010">How-to choose a WordPress Hosting Provider</a></li>
</ul>
<p><!-- Similar Posts took 3.443 ms --></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/some-supporthelp-for-akismet/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->