Saturday 18 December 2010

UserCake Automatic Login

UserCake Automatic Login
I just finished a little code snippet for the Open Source User log in system 'Usercake'.
It automatically logs in a new user upon successful registration by redirecting the page, automatically posting the username and password using document.form.submit (but only if there's no errors AND email activation is turned off).


Insert this code on register.php just before the <!DOCTYPE bit at around line 90.

if(!empty($_POST) && count($errors) == 0 && !$emailActivation){

      echo "<html>/n";
      echo "<head><title>Logging you In...</title></head>/n";
      echo "<body onLoad="document.forms['login_form'].submit();">/n";
      echo "<center><h2>Please wait, you are being logged in</center>/n";
      echo "<form method="post" name="login_form" ";
      echo "action="login.php">/n";

      echo "<input type="hidden" name="username" value ="$username" />/n";
      echo "<input type="hidden" name="password" value ="$password" />/n";
      echo "<center><br/><br/>If you are not automatically logged in ";
      echo "within 5 seconds...<br/><br/>/n";
      echo "<input type="submit" value="Click Here"></center>/n";
      
      echo "</form>/n";
      echo "</body></html>/n";
   
 } else {



And of course remember to close with a curly bracket right and the VERY END of the page.


I used this to pass an additional $_POST variable telling UserCake that it was the first login.


Hope this helps you!

1 comment:

  1. I had to refresh the page 2 times to view this page for some reason, however, the information here was worth the wait.

    ReplyDelete

Please keep it relevant or it won't show!