WordPress-Login via IP-address

Last week I took a closer look at WordPress to find out, whether I could use it as a multi-user blogging platform in my company. I had already tried LifeType, Drupal and WordPress Mu, but they all had their disadvantages (which I don’t want to explain at this point, but you may look here (German) if you are interested).

The only thing I needed, to make it as easy as possible for our employees to use the platform, was an automatic login via their IP-adresses. I use this way of authentication on some other sites on our intranet, too. I know, it is not a very secure way of authenticating your users, but as long as it is only a „free“ blogging platform for all employees of the company, all I needed was the users to be logged in automatically, when they visit the site.

After searching the internet for some time, I found no plugin that fit my needs, so I decided to create one myself. However, WordPress‘ API is very well documented and so after a short time, my plugin was finished.

Description

The plugin makes use of WordPress‘ wp_usermeta-table, where you can store all kinds of information about your users. All you need to do is create a field named ipaddress, that contains the corresponding user’s IP-address.

I did this via PHP in our Windows-logon script, but you are free to come up with any other way of inserting the IP-address into the table 🙂 The only problem is, that you have to find out the user’s ID in wordpress. In my case this is easy because WordPress and Windows usernames are the same, so I can search the wp_users-table for the current Windows username and return the ID.

I think by using the plugin Userextra you could even be able to enter the IP address manually into the user’s profile…

An example SQL-statement (2 is the ID of the user that will be logged in, if IP 172.16.123.124 visits the site):
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (50, 2, 'ipaddress', '172.16.123.124');

Of course you should not insert new rows into the table everytime an IP-address changes (use UPDATE instead).

Download / Source code

Ãœber uns Stefan

Polyglot Clean Code Developer

2 Kommentare

  1. Pingback:Stefan Macke » Blog Archiv » Wordpress als Blog-Plattform im Unternehmen

  2. Pingback:Wordpress-Login via IP-address » Stefan Macke

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax