GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   How to show a geoip warning page without using htaccess? (https://gfy.com/showthread.php?t=989953)

Darrell 09-30-2010 09:44 AM

How to show a geoip warning page without using htaccess?
 
Any tips on how to show a geoip warning page when someone visits a site without using htaccess? I don't want to use htaccess because of server load on high traffic sites.

Thanks :upsidedow

fris 09-30-2010 10:21 AM

http://www.maxmind.com/app/php

http://www.phpandstuff.com/articles/...ookup-with-php

BestXXXPorn 09-30-2010 10:28 AM

Indeed, MaxMind is kinda the defacto standard for GeoIP in terms of PHP :)

woj 09-30-2010 10:28 AM

can do it with php or javascript, dozens of ways actually depending on what exactly you are trying to acomplish...

Vick! 09-30-2010 10:30 AM

MaxMind of course. That's kickass.

BestXXXPorn 09-30-2010 10:36 AM

PHP Code:

<?
    $validCountries = array('US', 'CA', '...');
    $countryCode    = geoip_country_code_by_name($_SERVER['REMOTE_ADDR']);
    
    if(!in_array($countryCode, $validCountries)) {
        header('Location: http://www.someplace.com/country_not_aloud');
        exit();
    }
?>

Real quick down and dirty if you need an example (haven't tested but it should work)... List of country codes available here: http://www.maxmind.com/app/iso3166

Prasawet 09-30-2010 10:41 AM

U can use php & mysql IP database.
ip2nation.com, U can find instructions how to use, I found it 95% accurate, and U are not depend on the third party.

grumpy 09-30-2010 11:57 AM

Quote:

Originally Posted by Darrell (Post 17556318)
Any tips on how to show a geoip warning page when someone visits a site without using htaccess? I don't want to use htaccess because of server load on high traffic sites.

Thanks :upsidedow


.htaccess is the fastesT way and lowest server load, where do you get your info from?

SmokeyTheBear 09-30-2010 12:02 PM

Quote:

Originally Posted by grumpy (Post 17556748)
.htaccess is the fastesT way and lowest server load, where do you get your info from?

not nec. with no htaccess the page will load faster, the warning might be slower than simply using htaccess but i think his point is the page will initially load faster.

solution is to use an external file with htaccess geoip so the initial page loads faster.

i.e. instead of serving page after checking htaccess , serve page first , call htaccess from an external file such as a javascript

fris 09-30-2010 12:03 PM

or you can do it based on he language without any lib

BestXXXPorn 09-30-2010 12:24 PM

.htaccess should not ever be used unless you don't have control over your own web server...

In fact I'd highly recommend you don't run Apache... it's bloated and ass slow compared to newer web servers... You can't really beat nginx serving PHP via Fast-CGI. I've taken 12 box Apache deployments down to 4 nginx boxes and still had less load than all 12 boxes running Apache...

HomerSimpson 09-30-2010 03:09 PM

php + session
php or js + cookie

Darrell 10-03-2010 02:15 AM

Quote:

Originally Posted by fris (Post 17556769)
or you can do it based on he language without any lib

Thanks for all the replies. Based on language is a good idea.

My sites are in English and I only want to pop a warning page for one country and based on the browser language would be fine. Also I don't want to mess up my SE rankings. Is there a really simple way to accomplish this?

Darrell 10-03-2010 02:22 AM

With regards to not wanting to mess up SE rankings for showing a warning page for one specific country, would a Javascript redirect be a good idea as I don't think SE bots parse javascripts?

Darrell 10-03-2010 08:35 AM

Bump for me :upsidedow

fris 10-03-2010 08:53 AM

Quote:

Originally Posted by Darrell (Post 17565615)
Thanks for all the replies. Based on language is a good idea.

My sites are in English and I only want to pop a warning page for one country and based on the browser language would be fine. Also I don't want to mess up my SE rankings. Is there a really simple way to accomplish this?

Code:

<?php
$lang = ($_SERVER['HTTP_ACCEPT_LANGUAGE']);

if(preg_match("zh", $lang)) {
    header("location: http://www.domain.com/china.html");
} else {
    header("location: http://domain.com/");
}
?>



All times are GMT -7. The time now is 09:39 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc