How can I make my WordPress site redirect to subdomain once successfully login they will redirect back to root domain
When users visit my site they should login first through login form which i created in subdomain, once successfully login they will be redirected back to my root domain.
This is my subdomain -> http://login.anytimegear.co/
This is my rootdomain -> http://www.anytimegear.co/
This is my custom login form code.
$errorMsg = “”;
$validUser = $_SESSION[“login”] === true;
if(isset($_POST[“sub”])) {
$validUser = $_POST[“username”] == “admin” && $_POST[“password”] == “12345”;
if(!$validUser) $errorMsg = “Invalid Username & Password.”;
else $_SESSION[“login”] = true;
}
if($validUser) {
header(“location: http://www.anytimegear.co/login/“);
}
?>
and this is my code to redirect when user visited my site
add_action( ‘get_header’, ‘wpq_my_redirection’ );
function wpq_my_redirection() {
if ( ! is_user_logged_in() ) {
wp_redirect( ‘http://login.anytimegear.co/ ‘, 302 ); die();
}
}
This code has an error of too many redirects and i think the problem here it is because the code is redirecting back in forth.
How can i make login form When succesfully login they will redirected back to the root domain without having an issue of “too many redirects”.
Leave an answer