latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Automatic Login Based on IP not working

Home Forums Community Forum Automatic Login Based on IP not working

This topic contains 10 replies, has 3 voices. Last updated by  Bruce 4 years, 2 months ago.

Topic Author Topic
Posted: Wednesday Oct 31st, 2012 at 10:04 pm #30295
John Potter
Username: johnp

I’m trying a solution suggested in this thread about authentication by ip

I’ve tried adding your suggested mu-plugin Bruce, with a new ‘corporate’ user who has the correct s2Member role, and that ID added to the script.

My own IP address is in there for testing, but when I visit I do not get logged in as expected.

It also does not work when I try: $id = corporate;

I see the # Of Logins column of the Users admin page records zero for user ‘corporate’ after dozens of visits from my IP.

Any further advice you can offer would be appreciated, because this looks like it will probably meet my client’s needs.

List Of Topic Replies

Viewing 10 replies - 1 through 10 (of 10 total)
Author Replies
Author Replies
Posted: Thursday Nov 1st, 2012 at 8:49 pm #30369
Raam Dev
Username: Raam
Staff Member

Hi John,

Are you literally trying $id = corporate;? The $id variable is supposed to be assigned the database user ID of a specific user, which is a numerical value. So if you’re using “corporate“, that won’t work.

Also, you might want to try adding something like the following near the top of the script to see what IP is actually being reported when you visit the site:

<?php
	echo $_SERVER&#91;'REMOTE_ADDR'&#93;;
	exit;
?>

It could be that the IP being reported by your web server and the IP that you’re adding to the $ips array are different.

Posted: Sunday Nov 4th, 2012 at 11:31 pm #30616
John Potter
Username: johnp

Hi Raam

The complete line from the code that I tried at first was:

$id = 82; # The ID of the user you wish to log the visitor in as / Could also be User's Login

so you can see why I next tried the login: ‘corporate’.

The traffic tracking service verifies that my reported IP is correct.

Posted: Monday Nov 5th, 2012 at 5:52 pm #30699
Raam Dev
Username: Raam
Staff Member

Did you try checking what $_SERVER[‘REMOTE_ADDR’] reports? I believe that’s the variable that s2Member will be using to determine your IP address.

Posted: Monday Nov 5th, 2012 at 9:04 pm #30715
John Potter
Username: johnp

I just checked now, and yes, $_SERVER[‘REMOTE_ADDR’] also reports my IP address correctly.

Posted: Tuesday Nov 6th, 2012 at 6:15 pm #30813
Raam Dev
Username: Raam
Staff Member

A few other things I’d recommend checking:

1) Have you successfully logged in as that ‘corporate’ user in the normal way (e.g., using the login form)? You mentioned that the login column showed zero logins, so I suggest trying to login as that user at least once to make sure that much is working.

2) Have you tried disabling all other WordPress plugins? It’s possible there is a plugin conflict somewhere that’s preventing this from working properly. You may also want to see the Common Troubleshooting Tips.

Posted: Wednesday Nov 7th, 2012 at 4:05 pm #30933
John Potter
Username: johnp

OK Raam, I’ve found the problem – when I turn off the Quick Cache plugin I am automatically logged in as “corporate” (using the id in the script).

Unfortunately Quick Cache does not seem to have an option for configuring No-cache remote-address patterns.

But even if I proceed without a cache I’m no further ahead – even though “corporate” is a s2Member Level #2 there is still no access to protected content – I am referred to the “Membership Options” page when I try.

I also note there is no admin bar when logged in this way, and if I try to access wp-admin I am asked for a password.

The login page has a message:
“ERROR: The username field is empty.”
but actually the Username field has “corporate” pre-filled.

FYI this login also does not by-pass the Maintenance Mode plugin (not an issue for me).

Any further suggestions would be appreciated.

Posted: Wednesday Nov 7th, 2012 at 4:17 pm #30934
John Potter
Username: johnp

Correction – “corporate” user does, in fact, get access to protected posts, but NOT to restricted downloads.

My settings allow unlimited downloads for Level #2members.

Posted: Wednesday Nov 7th, 2012 at 11:20 pm #30993
Bruce
Username: Bruce
Staff Member

Hi John,

It is likely that the reason that this is not working for Level 2 Members is due to the way I had originally hooked WordPress. I had the plugin set up to automatically log in at the ‘init’ hook, which is one of the first hooks that WordPress fires. I have updated the hack to work on the ‘plugins_loaded’ hook which comes before ‘init’. Try the new code at:

http://www.s2member.com/forums/topic/automatic-login-based-on-ip/

This should solve your issue, but if it does not, I would consider changing line 18 to add_action('mu_plugins_loaded', 's2hack_auto_login_ip'); to get the absolute first hook available to you.

Posted: Wednesday Nov 7th, 2012 at 11:54 pm #30995
John Potter
Username: johnp

YES! It works now!

Thank you very much for your help Bruce.

It would be useful to others if you could update my original thread.

Posted: Thursday Nov 8th, 2012 at 12:25 am #30996
Bruce
Username: Bruce
Staff Member

No Problem and sorry for the mixup.

I’ll add a reply to the thread you linked letting others know about the bug.

Viewing 10 replies - 1 through 10 (of 10 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.