MyBB Community Forums

Full Version: Redirect user to custom login page after invalid username/password while login?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have made custom login page http://localhost/mybb/testlogin.php on which i have a form for login to forum. Now when user input wrong username/password then it takes me back to index.php page BUT instead i want to redirect it back to same login page i.e. http://localhost/mybb/testlogin.php.

How can i do this? Please help
paste your code here , i also create a custom login page for my mybb..

maybe i can help.

(2011-12-16, 03:08 PM)fakhrul Wrote: [ -> ]paste your code here , i also create a custom login page for my mybb..

maybe i can help.
When i use correct username/password then it is correctly taking me to welcome.php but when using wrong username/password it is redirecting me to testmember.php with usual login form of myBB at the top but i want to redirect it back to testlogin.php page printing message that your username/password is wrong.

This is my custom login page testlogin.php
<?php
chdir('forums'); // path to MyBB
define("IN_MYBB", 1);
require './global.php';
include('header.php');
if($mybb->user['uid'])
{
// The user is logged in, say Hi
echo "Hey, ".$mybb->user['username']."<br>
Thanks for logging in.";
}
else
{
?>
<form action="testmember.php" method="post">
Username : <input type="text" name="username" value="" /><br/>
Password : <input type="password" name="password" value="" /><br/>
<input type="submit" name="submit" value="Login" />
<input type="hidden" name="action" value="do_login" />
<input type='hidden' name='url' value='welcome.php' />
</form>
<?php
}
include('footer.php');
?>
This is my testmember.php
<?php
define("IN_MYBB", 1);
define('THIS_SCRIPT', 'member.php');
define("ALLOWABLE_PAGE", "login,do_login");
$nosession['avatar'] = 1;
require_once "./global.php";
require_once MYBB_ROOT."inc/functions_post.php";
require_once MYBB_ROOT."inc/functions_user.php";
require_once MYBB_ROOT."inc/class_parser.php";
$parser = new postParser;
// Load global language phrases
$lang->load("member");
// Make navigation
switch($mybb->input['action'])
{
case "register":
case "do_register":
add_breadcrumb($lang->nav_register);
break;
case "activate":
add_breadcrumb($lang->nav_activate);
break;
case "resendactivation":
add_breadcrumb($lang->nav_resendactivation);
break;
case "lostpw":
add_breadcrumb($lang->nav_lostpw);
break;
case "resetpassword":
add_breadcrumb($lang->nav_resetpassword);
break;
case "login":
add_breadcrumb($lang->nav_login);
break;
case "emailuser":
add_breadcrumb($lang->nav_emailuser);
break;
}
$do_captcha = $correct = false;
$inline_errors = "";
if($mybb->input['action'] == "do_login" && $mybb->request_method == "post")
{
$plugins->run_hooks("member_do_login_start");
// Checks to make sure the user can login; they haven't had too many tries at logging in.
// Is a fatal call if user has had too many tries
$logins = login_attempt_check();
$login_text = '';
// Did we come from the quick login form
if($mybb->input['quick_login'] == "1" && $mybb->input['quick_password'] && $mybb->input['quick_username'])
{
$mybb->input['password'] = $mybb->input['quick_password'];
$mybb->input['username'] = $mybb->input['quick_username'];
$mybb->input['remember'] = $mybb->input['quick_remember'];
}
if(!username_exists($mybb->input['username']))
{
my_setcookie('loginattempts', $logins + 1);
error($lang->error_invalidpworusername.$login_text);
}
$query = $db->simple_select("users", "loginattempts", "LOWER(username)='".$db->escape_string(my_strtolower($mybb->input['username']))."'", array('limit' => 1));
$loginattempts = $db->fetch_field($query, "loginattempts");
$errors = array();
$user = validate_password_from_username($mybb->input['username'], $mybb->input['password']);
if(!$user['uid'])
{
my_setcookie('loginattempts', $logins + 1);
$db->update_query("users", array('loginattempts' => 'loginattempts+1'), "LOWER(username) = '".$db->escape_string(my_strtolower($mybb->input['username']))."'", 1, true);
$mybb->input['action'] = "login";
$mybb->input['request_method'] = "get";
if($mybb->settings['failedlogincount'] != 0 && $mybb->settings['failedlogintext'] == 1)
{
$login_text = $lang->sprintf($lang->failed_login_again, $mybb->settings['failedlogincount'] - $logins);
}
$errors[] = $lang->error_invalidpworusername.$login_text;
}
else
{
$correct = true;
}
if($mybb->settings['failedcaptchalogincount'] > 0 && ($loginattempts > $mybb->settings['failedcaptchalogincount'] || intval($mybb->cookies['loginattempts']) > $mybb->settings['failedcaptchalogincount']))
{
// Show captcha image if enabled
if($mybb->settings['captchaimage'] == 1 && function_exists("imagepng"))
{
// Check their current captcha input - if correct, hide the captcha input area
if($mybb->input['imagestring'])
{
$imagehash = $db->escape_string($mybb->input['imagehash']);
$imagestring = $db->escape_string($mybb->input['imagestring']);
$query = $db->simple_select("captcha", "*", "imagehash='{$imagehash}' AND imagestring='{$imagestring}'");
$imgcheck = $db->fetch_array($query);
if($imgcheck['dateline'] > 0)
{
$correct = true;
}
else
{
$db->delete_query("captcha", "imagehash='{$imagehash}'");
$errors[] = $lang->error_regimageinvalid;
}
}
else if($mybb->input['quick_login'] == 1 && $mybb->input['quick_password'] && $mybb->input['quick_username'])
{
$errors[] = $lang->error_regimagerequired;
}
else
{
$errors[] = $lang->error_regimagerequired;
}
}
$do_captcha = true;
}
if(!empty($errors))
{
$mybb->input['action'] = "login";
$mybb->input['request_method'] = "get";
$inline_errors = inline_error($errors);
}
else if($correct)
{
if($user['coppauser'])
{
error($lang->error_awaitingcoppa);
}
my_setcookie('loginattempts', 1);
$db->delete_query("sessions", "ip='".$db->escape_string($session->ipaddress)."' AND sid != '".$session->sid."'");
$newsession = array(
"uid" => $user['uid'],
);
$db->update_query("sessions", $newsession, "sid='".$session->sid."'");
$db->update_query("users", array("loginattempts" => 1), "uid='{$user['uid']}'");
if($mybb->input['remember'] != "yes")
{
$remember = -1;
}
else
{
$remember = null;
}
my_setcookie("mybbuser", $user['uid']."_".$user['loginkey'], $remember, true);
my_setcookie("sid", $session->sid, -1, true);
$plugins->run_hooks("member_do_login_end");
if($mybb->input['url'] != "" && my_strpos(basename($mybb->input['url']), 'testmember.php') === false)
{
if((my_strpos(basename($mybb->input['url']), 'newthread.php') !== false || my_strpos(basename($mybb->input['url']), 'newreply.php') !== false) && my_strpos($mybb->input['url'], '&processed=1') !== false)
{
$mybb->input['url'] = str_replace('&processed=1', '', $mybb->input['url']);
}
$mybb->input['url'] = str_replace('&amp;', '&', $mybb->input['url']);
// Redirect to the URL if it is not testmember.php
redirect(htmlentities($mybb->input['url']), $lang->redirect_loggedin);
}
else
{
redirect("index.php", $lang->redirect_loggedin);
}
}
else
{
$mybb->input['action'] = "login";
$mybb->input['request_method'] = "get";
}
$plugins->run_hooks("member_do_login_end");
}
if(!$mybb->input['action'])
{
header("Location: testlogin.php");
}