Jump to content

Cannot get Login/Register to login user

Recommended Posts

Having problems with the new Login/Register module and hoping someone can help.

Desired result:

  • Guest lands on site (or later specific page) and is redirected to the Login page.
  • The user’s landing page is saved to a session and once logged-in, is redirected back to the original landing page

What’s happening:

  • Guest lands on any page on the site and is redirected to the Login page
  • Guest enters credentials, hits submit, then sometimes a variety of error messages get written to the logs including sessionCSRF and MYSQL errors. Guest user is presented with the Internal Server Error. Regardless, guest is not logged in


  • Using PW 3.0.76 and PHP 5.6


  • User account created manually in admin with login-register privilege
  • User is my old mate:


  • Site is configured to use delayed output with Regions & Functions API

In _init.php I have:

<?php namespace ProcessWire;
if(!$user->isLoggedin() && $page->id!=1193) { // not for login page
    $session->set('returnPage', $page->url);

In login.php template:

<?php namespace ProcessWire;

if($user->isLoggedin() && !$input->get('profile') && !$input->get('logout')) {
    // login and go back to the previous page or go to the home page
    $goToUrl = $session->returnPage ? $session->returnPage : '/';
} else {
    // let the LoginRegister module have control
    $content = $modules->get('LoginRegister')->execute();

<div id="regContent">
    <div class="content-wrap">
        <div class="container clearfix">
            <region id="regPostContent">
                <!-- Post Content
                ============================================= -->
                <div class="postcontent nobottommargin clearfix col_three_fourth">
                 </div><!-- .postcontent end -->
</div><!-- #content end -->


What am I doing wrong? Why can’t Fred login?

Any help to resolve much appreciated.




PS: Tried to use TracyDebugger to see what was happening but got js errors. Just not my day. Uninstalled TD and no errors :(

Edited by psy

Share this post

Link to post
Share on other sites

Tested your exact same code with ProcessWire 3.0.79 and PHP 5.6.25.

It works as expected with all kinds of users.

No entries in the logs or errors on the page.


Are there any security or session related functions or modules installed?

  • Like 2

Share this post

Link to post
Share on other sites

@wbmnfktr thanks for recreating the scenario - epic :) and also for the feedback.

Still more weirdness on my site and I have a horrible feeling the conflicting session-related module may be FormBuilder even though at one point, I removed all FB forms from the login page (there was one in the footer) and turned off SessionCSRF on all FB forms. :( Will keep working on it. Any other help/suggestions in the meantime most welcome

Share this post

Link to post
Share on other sites

Managed to get Login/Register working on a clean install with no FormBuilder with a few minor tweaks to the code:

Firstly, to be on the safe side, I changed $page->url to $page->httpUrl. Secondly, on occasion my frontend page named 'login' got confused with the admin page named 'login' so specified exactly where to redirect.

if(!$user->isLoggedin() && $page->id!=1193) { // not for login page
    $session->set('returnPage', $page->httpUrl);

Still having issues with SessionCSRF with LoginRegister + FormBuilder. Will post in the FB forum.


  • Like 1

Share this post

Link to post
Share on other sites

In order to complete the testing scenario I added a form to my login page now as well - embed method A, B, and C with FormBuilder form above and below login form.

Login still works fine without any errors.

  • Like 1

Share this post

Link to post
Share on other sites

@wbmnfktr Wow! Thank you again. I'm still having problems.  My forms are embedded via the API. Back to the drawing board :( 


Share this post

Link to post
Share on other sites

I saw your question in the FormBuilder linking to this thread, so replying here rather than there because I don't think it's related to FormBuilder, as it doesn't look like you are using FormBuilder for the forms here and as a result it shouldn't come into play. A couple things to look into: I'm wondering if there is an unexpected extra redirect occurring somewhere. It might be good to watch your developer tools Network tab (in Chrome) to look for 301 requests. It could be as simple as a page requiring a trailing slash and one not being present, or the opposite, and thus a redirect occurring. Or it could be that you've got those pages access protected using PW's template access control, and its redirects are happening before your _init.php even gets called. While you are testing, you might want to disable the _init.php code just to see what difference it makes.

Take a look at markup regions and make sure that your final output is as you expect when viewing the source of the pages. I noticed you are using the markup region tag termination hint <!--#regPostContent-->, which is good—that gives Markup Regions a shortcut to find where your tag ends, saving it time. But in another case you are using <!-- #content end -->, which might be confusing the markup regions because it should instead be <!--#regContent-->, and I don't see a <div id='content'> in the markup you pasted in. I think markup regions is probably just ignoring your <!-- #content end -->, but try replacing it with <!--#regContent--> just in case. 

  • Like 1

Share this post

Link to post
Share on other sites

Thank you @ryan for pointing me in the right direction. Problem solved.

FormBuilder was a red herring, all good there. The cryptic debug message was key to finding the cause.


Fatal error: Uncaught PDOException: You cannot serialize or unserialize PDO instances in [no active file]:0 Stack trace: #0 [internal function]: PDO->__sleep() #1 [internal function]: session_write_close() #2 {main} thrown in [no active file] on line 0

I refer to the home page throughout the site and normally add $homePage = $pages->get('/'); in the _init.php file.

Tried to be too clever and tweak page load speed by reducing the number of database calls so put the following below the LoginRegister code:

// shortcut to home page saved in session
$homePage = $session->get('home-page');  // Fairly certain this is the culprit!
if (!$homePage) {
    $homePage = $pages->get('/');
    $session->set('home-page', $homePage);

While the above works for $cache, it doesn't for $session, or even replacing $session with $_SESSION and using array_key_exists('home-page', $_SESSION), etc.

Reverted to $homePage = $pages->get('/'); for every page and Login/Register working perfectly. 

  • Like 3

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By angelo, italy
      Hi guys,
      I've always used WP but I want to swtich to PW. I'm not sure ....
      I'd like to know if it's possible to create a website for an online photo contest.
      The participants of the competition could create their own account, in which they upload their photos. The photos uploaded remain visible only to themselves and the judges.
      From their account they can make the "entrance fee" payment.
      The judges of the competition can create their own account... entering they see the photos of the participants and vote photos
      At the main page I imagine the title of the competition, a button to read the regulation, and a button to register.
      The website should be in Italian and English.
      Thank you!!
    • By Peter Knight
      I have a demo site which I moved to a new VPS for client testing
      We noticed that leaving a page open and then revisiting the site can result in a 25 second(ish) to load time and will then throw a 500 Error.
      The hosting guys had a look and confirmed that the server is fine but the issue could be related to authentication or sessions.
      We are running Page Protector and ProCache so I wondered if there were any known bugs here and any recommended actions.
      My actual PW log doesn't show anything but the server log has plenty of these
      2018-12-06 08:14:00 Error xxx.141.1x.101 500 POST /who-we-are/ HTTP/1.0     1.58 K Apache access 2018-12-06 08:14:45 Warning xxx.141.1x.131   mod_fcgid: read data timeout in 45 seconds, referer: http://demo.abc.not/who-we-are/       Apache error 2018-12-06 08:14:45 Error xxx.141.1x.131   End of script output before headers: index.php, referer: http://demo.abc.not/who-we-are/       Apache error 2018-12-06 09:03:18 Error xxx.141.1x.131   2614#0: *667 recv() failed (104: Connection reset by peer) while reading response header from upstream       nginx error Thanks
    • By Marcel
      Hey all,
      I want to customize the mywebsite/processwire/profile page. It's almost all good but I want to get rid of the sections 'Admin Theme' and 'Language' so that the user can just set a new password. (see image)
      Do I have to modify the admin template or how can I do that? Because when I go tree>Admin>Profile there are no fields to add or remove.
      Or where can I find the php file?
      I would appreciate your help.

    • By ridgedale
      Reference: PW 3.0.111 and uikit3 based site using the Regular-Master profile.
      I'm trying to automatically redirect a logged-in user to a custom profile page using $session->redirect() and need to add $user->name to the redirect path.
      All my attempts appear to have failed:
      $session->redirect('/user-profile/')->name; $session->redirect('/user-profile/')->$user->name; $session->redirect('/user-profile/' . get($user->name . '/')); $session->redirect('/user-profile/' & get($user->name)); Can anyone point out where I am going wrong?
    • By matsn0w
      Hey all,
      I am working on a website and I want to style the login page, but I'm a bit confused. 
      I want either the existing login page styled in my own way using some CSS (I guess I prefer that) or I want to create a custom page with a form to login. (Which I could style too).
      I used the code from Ryan and Renobird posted here - which works great - but that doesn't replace the original login page. 
      Is there a way to some sort of 'disable' the original login?
      I hope my question is clear and thanks in advance,
  • Create New...