...

View Full Version : redirect with message in case of failed login



kotak86
11-21-2011, 04:31 AM
Hi All

I am newbie in php and I want trying to make login application and I came to below issue:

1. In case of failed login how to redirect user in same page with meg like username and password do not match.
At this moment I have used header function but it simply redirect to my index.php(which is in fact login page)....but I want it with message....

Thanks
if(isset($_POST['uname']) && isset($_POST['passwd']))
{

$usrname = $_POST['uname'];
$passwd = $_POST['passwd'];
$pass_haas =($passwd);
if(!empty ($usrname) && !empty($passwd))
{
$query = "SELECT * FROM `user_info` WHERE `uname` = '$usrname' AND `passwd` = '$pass_haas' ";


$query_run = mysql_query($query);


$query_num_rws = mysql_num_rows($query_run);



if($query_num_rws == Null)
{

header('Location:login.php');

}
else if ($query_num_rws == 1)
{
$user_id = mysql_fetch_assoc($query_run);

$user_name = $user_id['g_name'];


$_SESSION['g_name'] = $user_name;


header('Location:welcome.php');

}

}
else
{
echo 'You must supply user name and Password';
}
}

Adee
11-21-2011, 04:47 AM
at the top of the login page you can put smething like


if(isset($_GET['failed'])) { if($_GET['failed'] == 1) { echo "Your login failed."; } }

then change the header to header('location:login.php?failed=1');

kotak86
11-21-2011, 05:09 AM
Thank you..It works



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum