0

I am trying to create a company intranet site. I don't want to have to create a multitude of users for the site and would prefer to just only allow access if you are on an IP or if offsite then you have to login. This will narrow down the users to only those that work from home etc. I was hoping to use a redirect to the auth page if you do not match with logged in or an ip number or array of numbers. I would prefer not to use a plugin.

  function intranet( ) {
    $whitelist = array('192.168.0.1', 192.168.0.2);
      if ( ! is_user_logged_in() || !in_array($_SERVER['REMOTE_ADDR'], $whitelist) ) {
            auth_redirect();
    }
}

However it does not appear to work. I have read suggestions on using .htaccess, but this will restrict to whole site to the IP

deny from all
allow from 98.6.000.111

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

As far as i can tell this method wont let me access the site from outside via a login option. Any help appreciated Thank you.

2 Answers 2

0

Simple you can use this WordPress plugin restricted-site-access

this plugin "Limit access your site to visitors who are logged in or accessing the site from a set of specified IP addresses" - by plugin author.

1
  • Thank you, but I am unable to use a plugin for company reasons. However the exact functionality of this plugin is what I am trying to achieve
    – Dan
    Nov 13, 2019 at 14:13
0

Well, I have managed it. I don't know how this is any different in a sense to my opening question but it works none the less.

  function intranet( ) {
    $whitelist = array('0.0.0.1', '0.0.0.2'); 
    if (in_array($_SERVER['REMOTE_ADDR'], $whitelist)) {
       // do nothing
      }
    else {
        if(is_user_logged_in()) {
            //do nothing
        }
        else {
            auth_redirect();
        }
    }
}

Hope this helps anyone else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.