403 Error Upon Logging In
-
When trying to log in as a customer/subscriber, I’m sent to a 403 Error Page that reads:
403 Forbidden Error Page
If you arrived here due to a search or clicking on a link click your Browser’s back button to return to the previous page. Thank you.
After pressing the back button, it returns me to the site and I’m successfully logged in. Logging out goes smoothly. I’ve spent a few hours looking around and trying solutions but to no avail.
-
Are you using any additional Bonus Custom Code or any other personal/custom htaccess code?
Are you using another login plugin or login security plugin?
Do you have a membership plugin installed?
Does your theme do anything with login processing? ie a membership theme?1. I’ve got the following code in my theme’s functions.php file.
// Woocommerce Login Redirect
add_filter(‘woocommerce_login_redirect’, ‘wc_login_redirect’);function wc_login_redirect( $redirect_to ) {
$redirect_to = ‘<?php echo get_permalink(); ?>’;
return $redirect_to;
}2. I’m using this Recaptcha plugin.
3. No membership plugin installed.
4. Theme does not do anything with login processing and is not a membership theme.
Ok comment out the woocommerce filter in your theme’s functions.php file to see if that redirect is causing the issue. Logically doing a redirect after login should not cause a 403 error. Let me know the results.
Was going to test that recaptcha plugin but it requires too many hoops to jump through. yep I am just as lazy as the average person so if you ask me to sign up for anything that is probably not going to happen. ha ha ha 😉
Strange – I tried removing the code before originally posting this and it didn’t have an effect. Now when I remove the code from my functions.php, everything goes smooth.
Any recommendations on redirecting users to page they logged in from? I used to use Theme My Login but if a quick snippet can do the trick, I’d prefer going that way.
Thanks again for your prompt and helpful responses.
My hunch is that the hook you are using is either incorrect or invalid in some way. Give this code a whirl and/or modify it for your intended usage.
Example of using a standard/basic WP login_redirect hook:
// redirect non-admins somewhere function example_redirect( $redirect_to, $request, $user ) { global $user; if ( isset( $user->roles ) && is_array( $user->roles ) ) { if ( in_array( 'administrator', $user->roles ) ) { // redirect to /wp-admin return $redirect_to; } else { return site_url('/somewhere/'); } } else { return $redirect_to; } } add_filter( 'login_redirect', 'example_redirect', 10, 3 );I’m sorry – I’m having a hard time figuring out how to implement a redirection to the page the subscriber/customer has logged in from with the code provided.
I understand the gist of it but what exact code would I need in order to redirect user to the page they were on when logging in?
If you can’t help, no worries! I understand it’s not your duty to 🙂
Yeah that is a neat thing. bbPress or BuddyPress does this very eloquently so just dissect that code. 😉
joinfof,
I believe I can help you. The following line doesn’t make sense, because you are already inside the PHP interpreter when you set that redirect. The “<?php” part indicates that the interpreter should be “turned on” for this part of the file, but it is already on.
$redirect_to = '<?php echo get_permalink(); ?>';Try changing it to:
$redirect_to = get_permalink();Yours,
Joe.I tried that and it didn’t work. No worries, I’ll keep at it. I can’t seem to find the exact snippet I need and PHP is my weakness. Thanks again!
I should have some spare time in a few hours from now so I will grab the magical BuddyPress code that does what you want. If I can’t get to that today then definitely by tomorrow. 😉
Sounds like a plan to me – thanks for going above and beyond!
Looking at the BuddyPress code it redirects based on where the user last was generally, which is obviously the best way to do something like this, but adds a level of complexity, which may not be possible if you do not have an existing framework. Or of course if you have finite URI’s then you could probably do a switch that is URI based. Giving that theory a whirl on a non-framed site.
Would basically be something like this. 😉
// redirect non-admins somewhere function example_redirect( $redirect_to, $request, $user ) { global $user; if ( isset( $user->roles ) && is_array( $user->roles ) ) { if ( in_array( 'administrator', $user->roles ) ) { // redirect to /wp-admin return $redirect_to; } else { switch ( esc_html($_SERVER['REQUEST_URI']) ) { case preg_match( '/some-uri/', esc_html($_SERVER['REQUEST_URI']), $matches ): // redirect somewhere break; case preg_match( '/some-other-uri/', esc_html($_SERVER['REQUEST_URI']), $matches ): // redirect somewhere break; } return site_url('/somewhere/'); } } else { return $redirect_to; } } add_filter( 'login_redirect', 'example_redirect', 10, 3 );
The topic ‘403 Error Upon Logging In’ is closed to new replies.