Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To limit access based on certain file, use the following:</p> <p><strong>Example:</strong></p> <pre><code>&lt;Files wp-login.php&gt; order deny,allow deny from all allow from 139.82.0.0/16 &lt;/Files&gt; </code></pre> <hr> <p>To be able to use geolocation and redirect a client based on country use <a href="http://dev.maxmind.com/geoip/legacy/mod_geoip2/" rel="nofollow"><code>mod_geoip2 Apache module</code></a>:</p> <p><strong>Example:</strong></p> <pre><code>GeoIPEnable On GeoIPDBFile /path/to/GeoIP.dat # Redirect one country RewriteEngine on RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$ RewriteRule ^(.*)$ http://www.canada.com$1 [R,L] # Redirect multiple countries to a single page RewriteEngine on RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(CA|US|MX)$ RewriteRule ^(.*)$ http://www.northamerica.com$1 [R,L] </code></pre> <hr> <p>Another solution is to manually insert a list of IPs that would be blocked. There is online service called <a href="http://incredibill.me/htaccess-block-country-ips" rel="nofollow"><strong>HTACCESS Block Country by IP Range</strong></a> that would generate for you a list of IPs to block.</p> <p><strong>Example:</strong></p> <pre><code># BLOCK COUNTRY BY IP RANGE # IncrediBILL's HTACCESS Tools # http://incredibill.me &lt;Limit GET POST HEAD&gt; order allow,deny # # Block from BRAZIL (BR) # deny from 139.82.0.0/16 deny from 143.54.0.0/16 deny from 143.106.0.0/16 deny from 143.107.0.0/16 deny from 143.108.0.0/16 deny from 146.134.0.0/16 deny from 146.164.0.0/16 deny from 147.65.0.0/16 deny from 150.161.0.0/16 deny from 150.162.0.0/16 deny from 150.163.0.0/16 </code></pre> <hr> <p><strong>One more possible and most appropriate solution for you, would be using <em>PHP</em> <a href="http://www.php.net/manual/en/book.geoip.php" rel="nofollow"><code>geoip module</code></a>, because you want to limit a user an access to certain parts of the page and doing it using <em>PHP</em> is much better.</strong></p> <p>First of all, install <a href="http://www.php.net/manual/en/geoip.installation.php" rel="nofollow"><em>php-pecl-geoip</em> module for PHP</a>. Depending on your server configuration, installation is usually straight-forward. If you are using <em>RedHat/CentOS</em> simply run: <code>yum install php-pecl-geoip</code>. You must have root access to your server to install software, if you are using shared hosting, ask your administrator to do it for you.</p> <p>After installation, you will have a whole new <a href="http://www.php.net/manual/en/ref.geoip.php" rel="nofollow">set of PHP functions</a> available for you. The one you should use at the moment is <code>geoip_continent_code_by_name()</code>, as you asked to block all users from <em>South America</em>.</p> <p>Applying it to your example is easy:</p> <pre><code>if ( geoip_continent_code_by_name( $_SERVER['REMOTE_ADDR'] ) == 'SA' ) { echo '&lt;a href="#"&gt;YouTube Video Example: This video is not available for South America.&lt;/a&gt;'; } else { echo '&lt;a href="http://www.youtube.com/watch?v=videoCode"&gt;YouTube Video Example&lt;/a&gt;'; } </code></pre> <p>To test it on you server, you could just replace <code>$_SERVER['REMOTE_ADDR']</code> with one of the IPs that belong to Brazil, e.g.: <code>geoip_continent_code_by_name('146.164.22.1');</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload