IP login

Permalink
Hi there!

I have a client who's got a site that you have to login to. Now they want to let a school login just through the IP-address. I have no idea how to get this to work, even though I've spent a lot of time googling for the solution. (Drupal has a module for it, but that doesn't help, I mean, why should I use Drupal?)

Can anyone help me, in any way?

Cheers,
Stefan

stecal
 
Mainio replied on at Permalink Reply
Mainio
There isn't an add-on but you can achieve this pretty easily.

Just create your own custom package for this and add hook into the package's on_start method, something like this:
public function on_start() {
   global $u; // Current user
   if (!$u->isLoggedIn()) {
      // Add in this list the user ID => ip mappings
      // for your users
      $ipList = array(
            123 => array("123.123.123.123")
      );
      foreach ($ipList as $uID => $ips) {
         if (in_array($_SERVER['REMOTE_ADDR'], $ips) {
            // Login the user
            $u = User::getByUserID($uID, true);            
            break;
         }
      }


Hope this helps. Good luck!


Antti / Mainio


EDIT: Of course if you need wildcards etc. you need to add stuff but I think you can get the idea from the example.
stecal replied on at Permalink Reply
stecal
Mainio, thanks a lot for your very fast answer!
I'll try to do that, even though I've never made a package before... I'll let you know how it goes.

- Stefan