Jump to content


- - - - -

GeoIP


  • Please log in to reply
7 replies to this topic

#1 Ingenious

Ingenious

    IPB Newbie

  • Visitors
  • Pip
  • 34 posts

Posted 01 May 2011 - 03:44 PM

I currently use VB3 and to prevent non-UK registrations I use a few lines of code that makes use of GeoIP. On VB this is easy since the registration process is a separate PHP file and I can just stick the code at the start. Non-UK IP addresses abort the page to a "Thanks, but you can't register" error page.

I see on IPB everything is done through the index.php file - does that mean it's going to be harder to do this with IPB? Or is the registration part easy to find and add my lines of code to it. Or is there a better solution (hooks, plugins etc) that can stop the registration?

$ip=$_SERVER['REMOTE_ADDR'];
$country = geoip_country_code_by_name($ip);
if ($country!="GB"){
header('Location: http://www.link to an error page');
exit;
}

It's vital this ONLY aborts on attempts to register and does not interfere with guests viewing the rest of the forum. In its current form this also only works at the start of the page (as it outputs a header to redirect).

#2 Michael

Michael

    Member Title intentionally left blank

  • Marketplace Moderator
  • PipPipPipPipPipPipPipPipPip
  • 17,430 posts

Posted 01 May 2011 - 05:36 PM

I don't know that any hook exists for this currently, but it'd be easy enough to create one.  Otherwise, one could simply stick that code into the file that handles IP.Board's registration.  Everything does get routed through the index.php file in IP.Board, but you can always modify those other files to affect just the areas they control.
Michael McCune - IPS Marketplace Moderator

My Stuff: My Forum · My Resources · My Tutorials
Contact Me: Email · Facebook · Twitter · Google+
Follow Invision Focus: On Facebook · On Twitter

#3 Ingenious

Ingenious

    IPB Newbie

  • Visitors
  • Pip
  • 34 posts

Posted 02 May 2011 - 06:27 AM

Thanks Michael.

My concern in putting that code within the index.php file is that I won't be able to redirect to an error page. So I assume I'd have to just exit the script to stop it, which isn't very pretty but will do the job.

Does anyone else have any useful info/help for this?

In particular if there is any critical reason why this won't work I'd like to know :)

#4 Michael

Michael

    Member Title intentionally left blank

  • Marketplace Moderator
  • PipPipPipPipPipPipPipPipPip
  • 17,430 posts

Posted 02 May 2011 - 06:34 AM

If your error page is somewhere else on the forums, then when it tries to redirect to that error page it's going to again check this GeoIP info and will again try to redirect the user, causing an infinite loop.  If, however, the code is added into the PHP file for the registration process, it won't do that (provided the error page you're sending them to is not part of that registration PHP file too).
Michael McCune - IPS Marketplace Moderator

My Stuff: My Forum · My Resources · My Tutorials
Contact Me: Email · Facebook · Twitter · Google+
Follow Invision Focus: On Facebook · On Twitter

#5 RobertMidd

RobertMidd

    I want that one

  • +Clients
  • 3,987 posts

Posted 02 May 2011 - 07:21 AM

You might be able to put this into the index.php by using an if statement.

if (ipsRegistry::$request['section'] == 'register'){
   $ip=$_SERVER['REMOTE_ADDR'];
   $country = geoip_country_code_by_name($ip);
   if ($country!="GB"){
	  header('Location: http://www.link to an error page');
	  exit;
   }
}


#6 .Nuno.

.Nuno.

    Advanced Member

  • +Clients
  • 497 posts

Posted 02 May 2011 - 08:30 AM

Hello,

I haven't tried and I don't know if the country code is correct, but why not .htaccess or apache conf?

<IfModule mod_geoip.c>
  GeoIPEnable On
  GeoIPDBFile /path/to/GeoIP.dat
 <Files "index.php">
   RewriteEngine on
   RewriteCond %{QUERY_STRING} ^app=core&module=global&section=register$
   RewriteCond %{ENV:GEOIP_COUNTRY_CODE} !^UK$
   RewriteRule ^(.*)$ http://www.domain.com/whynot.html [L]
 </Files>
</IfModule>


#7 Mat B

Mat B

    GROUP BY fail

  • Visitors
  • PipPipPipPipPip
  • 570 posts

Posted 02 May 2011 - 08:41 AM

For what it's worth, this could be achieved with a very simple hook of public_core_global_register, to check the country and either call output->showError to bail out (using the standard IPBoard error page), redirect to another page explaining the issue, or call the original registration form.

I won't go into specific detail, but suffice it to say that it will be very easy to do, and unlike the file edit you performed previously, with IPBoard you will only have to do it once as hooks survive upgrades without modification in most cases.
Mat Barrie
Mobile Applications Developer
Invision Power Services, Inc
Get the IPB iPhone App | Email Me | Twitter

#8 Ingenious

Ingenious

    IPB Newbie

  • Visitors
  • Pip
  • 34 posts

Posted 02 May 2011 - 11:13 AM

Mat B - many thanks for that, at least I know this can be done with a hook (which is the best solution as you say it will survive an upgrade!). Although I haven't the foggiest how it all works at least I know when I purchase I can ask in the support forums. I am sure the method would also be useful for other people, or those who want to screen certain countries (spammers etc).

And thanks for the suggestion about .htaccess, I had not thought about using that to spot that file being called, that could be a useful fall back :)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users