5

As many of you know WPEngine don't support PHP SESSIONS unless the user is logged in. In that case WPEngine start taking consideration of PHP SESSIONS and the software based on hybridauth like Wordpress Social Login or Wordpress Social Invitations will work ok.

So my question is : There is a way to fake a Wordpress login?

2 Answers 2

4

You could create a dummy user (with no rights) and log in every visitor using this dummy user. This could be done pretty easily:

wp_set_auth_cookie($uid, true);
wp_set_current_user($uid);

But in my opinion that's a rather flawy workaround.

Your main problem is that all pages for not-logged-in users come from the page-cache. That also means that all users get the same html output as long as there is page-caching active. So there can't be any difference to your pages based on the visitor. All visitors get the same output.

A better way would be to create a ticket at WPEngine and ask them to disable page-caching for your site. That's actually also the way they suggest on the page you linked to.

5
  • I don't have am account on WPengine, just my plugin users got. The idea of this is that the user should appear not logged to Wordpress, but logged to WPengine :D
    – chifliiiii
    Jul 13, 2013 at 20:15
  • Ah I see. Seems like WPengine is using the wordpress login cookie to determine if one is logged in or not: WordPress sets cookies related to that login, and our system is set up to recognize those WordPress login cookies. You may have a chance in creating a fake cookie with an invalid session. If WPEngine is only looking for the existence of the login cookie. But this seems like a really dirty hack, that could break other tings. Maybe you should just tell your users to contact WPEngine and let them disable caching (place it in your FAQ or something).
    – s1lv3r
    Jul 15, 2013 at 8:57
  • 1
    Exactly, im looking for a dirty hack :)
    – chifliiiii
    Jul 15, 2013 at 14:11
  • 3
    :-P Then you may try to create a cookie named wordpress_logged_in_{random_md5_1} and value user|{current_timestamp}|{another_random_md5_2} and an cookie wordpress_{random_md5_1} and value user|{current_timestamp}|{another_random_md5_3}. You won't be really logged in as you don't have a real session, but if WPEngine only looks for the existence of a session cookie as stated in their docs, there's a good chance that they'll eat it.
    – s1lv3r
    Jul 15, 2013 at 14:21
  • 1
    Derivation of ideas discussed in this thread, which for now is working for our needs on WPEngine: gist.github.com/wkw/6fc5aeb598ec0c1aa151 I took the idea of a fake user-session cookie and am using it to selectively enable/disable caching for dynamic content.
    – wkw
    Oct 6, 2015 at 2:23
2

A quick and hacky solution is to put this in your header include file:

<?php
  // Re-enable sessions for WPEngine
  setcookie('wordpress_logged_in_' . md5("test"), md5("random"), time()+3600);
?>

It's wrong, but it works.

0

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.