Jeremy Stein - Brain

« »

WordPress Auto-login

My family blog requires a log-in, but certain elderly relatives don’t understand how to enter a username and password into the log-in page. So, instead I send them links like this: When they click the links, it logs them in with “Remember Me” selected.

I added the following line to my .htaccess file:

RewriteRule ^l/(.+)/(.+)/?$ /auto-login.php?log=$1&pwd=$2 [QSA,L]

Then I created auto-login.php:

    <title>Family Notes</title>
    <script language="javascript">
      function send() {
  <body onload="send()">
    <form name="loginform" id="loginform" action="/wp-login.php" method="post">
      <input type="hidden" name="log" value="<?php echo $_GET["log"]; ?>"/>
      <input type="hidden" name="pwd" value="<?php echo $_GET["pwd"]; ?>"/>
      <input type="hidden" name="rememberme" value="forever"/>
      <input type="hidden" name="wp-submit" value="Log In"/>
      <input type="hidden" name="redirect_to" value="/"/>
      <input type="hidden" name="testcookie" value="1"/>
      <noscript><input type="submit" name="ignore" value="Log in"/></noscript>

(The form input names are copied from wp-login.php. You may want to check yours as it can change between releases.)

August 6, 2008 3 Comments.


  1. Kobus replied:

    Thank you for this! I didn’t get it to work with .htaccess, but I created the auto-login.php and used

    July 15th, 2011 at 6:58 am. Permalink.

  2. JA replied:

    Am using 3.3.1 and can confirm the form input names still work
    I added a third element to the URL that also adds a redirect to a specific page (I’m sending the link to certain users I want to fill out a gravity form)

    As with Kobus above, I also couldn’t get the rewrite to work. In my application my WordPress is installed in a subfolder so i suspect I need to do more reading so I understand the rewriteRule better. Thank you to Kobus then for spelling out what the URL should be. It’s not as pretty or as short, but works.

    May 24th, 2012 at 1:39 pm. Permalink.

  3. Stefan Zedlacher replied:

    works with v. 3.3.4 also. Great work, thought this should work but your script solved my errors!
    big THX

    October 4th, 2012 at 11:04 am. Permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

Why ask?

« »