<?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; ip2nation</title>
	<atom:link href="http://www.web-development-blog.com/archives/tag/ip2nation/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>Save bandwidth with PHProxy and ip2nation</title>
		<link>http://www.web-development-blog.com/archives/save-bandwidth-with-phproxy-and-ip2nation/</link>
		<comments>http://www.web-development-blog.com/archives/save-bandwidth-with-phproxy-and-ip2nation/#comments</comments>
		<pubDate>Wed, 30 May 2007 12:57:52 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[PHP scripts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[bandwidth]]></category>
		<category><![CDATA[hosting]]></category>
		<category><![CDATA[ip2nation]]></category>
		<category><![CDATA[proxy]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/archives/save-bandwidth-with-phproxy-and-ip2nation/</guid>
		<description><![CDATA[If your website becomes a little busy the websites bandwidth becomes very valuable. If your visitors using too much bandwidth and the conversions from your website are very low or just moderate, it&#8217;s possible that you get broke with also a good internet website project. During the last month the web proxy business was a [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><p>If your website becomes a little busy the websites bandwidth becomes very valuable. If your visitors using too much bandwidth and the conversions from your website are very low or just moderate, it&#8217;s possible that you get broke with also a good internet website project. During the last month the web proxy business was a very hot item with thousands of new web proxies every day. Since it&#8217;s not allowed to place Google ads on the proxified pages, it&#8217;s very difficult to find alternatives which pay enough that you can pay your hosting bills. One of them is <a href="http://www.adversal.com/rindex.jsp?t=0&amp;c=283085d30e10513624c8cece7993f4de">Adversal</a>, they pay a moderate amount for traffic generated by US, UK or CA visitors. But what if your traffic and bandwidth is mostly used by visitors from other countries? In this case the visitors using your server resources and visitors from your target group are maybe not able to use one of your fast web proxies.</p>
<p>With the proxy script PHProxy (version 0.5b2 from 20th January 2007) and the data IP location database  from ip2nation it&#8217;s very easy to block visitors which are coming from other countries then your target group. In this tutorial you will learn how to add the required code to your PHProxy powered proxy website.<span id="more-99"></span></p>
<p><a href="http://www.proxyservice.de/"><img src="http://www.proxyservice.de/images/banner_468_60.jpg" height="60" width="468" /></a></p>
<p>First we need to prepare the MySQL database, download and install the <a href="http://www.ip2nation.com/">ip2nation</a> database table dump. Use phpMyAdmin to import the database tables inclusive the data.</p>
<p>The PHProxy script comes with two php files index.php and index.inc.php, first we need to add the following code to the index.php (script) file:</p>
<p><code>$DBHOST = '';<br />
$DBUSER = '';<br />
$DBPASS = '';<br />
$DATABASE = '';<br />
$my_countries = array('us', 'ca', 'gb');<br />
$use_ip2nation = true;<br />
</code><br />
The first four variables are used for the database connection, the array indicates the countries you want to allow access to your proxy and the last Boolean variable is used to switch the country block on or off (this way you don&#8217;t need to remove all code).</p>
<p>Next we need to add this code just below the function proxify_css_url (must be around row 325):<br />
<code><br />
if ($use_ip2nation) {<br />
$db = mysql_connect($DBHOST, $DBUSER, $DBPASS);<br />
mysql_select_db($DATABASE);<br />
$sql = "SELECT country FROM ip2nation WHERE ip &lt; INET_ATON('".$_SERVER['REMOTE_ADDR']."') ORDER BY ip DESC LIMIT 0,1";<br />
$res = mysql_query($sql);<br />
$country = mysql_result($res, 0, 'country');<br />
mysql_free_result($res);<br />
if (!in_array($country, $my_countries)) {<br />
show_report(array('which' =&gt; 'index', 'category' =&gt; 'error', 'group' =&gt; 'resource', 'type' =&gt; 'non_us'));<br />
}<br />
}<br />
</code></p>
<p>This code will query the database and compares the IP address from the client with the collected data. If the resulting country code exists in your list of country codes the script will continue and otherwise an error (code &#8220;non_us&#8221;) is stored in the error message array.</p>
<p>OK, next we need to add some code to the index.inc.php (template) file. At the top of the file, we need to add this variable to tell script to show the web form:</p>
<p><code>$show_web_form = true;</code></p>
<p>Next locate the PHP code part with all the error message code and add this error information below the break for the message which is defined for &#8220;hotlinking&#8221;:</p>
<p><code>case 'non_us':<br />
$message = 'We sorry, our service is currently not available.<br />
Please try a different proxy via the topsite buttons in the websites footer.';<br />
$show_web_form = false;<br />
break;<br />
</code></p>
<p>Together with this message the Boolean to hide the web form is set to &#8220;false&#8221;. This part is actually not required for blocking visitors, but makes the whole thing more complete. Around the form we need to create a condition which will show the form or not, add before the form openings tag this code (if):</p>
<p><code>if ($show_web_form) {</code></p>
<p>And below the form ending tag this alternative code (else):</p>
<p><code>} else {<br />
// place here some alternative content<br />
};<br />
</code></p>
<p>Add some ad or banner in the html which will show up if the resulting country code is not in the country (white) list. Because this function is called with every execution and if the error code exists it is not possible for visitors from &#8220;not allowed&#8221; country to view a proxified page.</p>
<p>Check our partner <a href="http://www.proxies2u.com/templates.php">Proxies2u.com</a> for the complete solution.<strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/upload-images-for-usage-in-tinymce/" rel="bookmark" title="September 25, 2008">Upload images for usage in TinyMCE</a></li>
<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/upload-in-modal-window-and-pass-values-with-jquery/" rel="bookmark" title="September 5, 2009">Upload in modal window and pass values with jQuery</a></li>
</ul>
<p><!-- Similar Posts took 3.200 ms --></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/save-bandwidth-with-phproxy-and-ip2nation/feed/</wfw:commentRss>
		<slash:comments>7</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! -->