Page 1 of 1

Successful login redirect

Posted: Sat Aug 15, 2009 10:11 pm
by Hutch
I would like to redirect after successful login. I can redirect with correct username and any password. If I enter no password it takes me to "Wrong username or password". Can you help me fix it to match both?




<?php
include_once 'connect.php';
session_start();

if (isset($_POST['submit']))
{
$player=$_POST['player'];
$password=$_POST['password'];
$player=strip_tags($player);
$password=strip_tags($password);
$password=md5($password);

$query = "select name,password from members where name='$player' and '$password'";
$result = mysql_query($query) or die("Could not query players");
$result2 = mysql_fetch_array($result);
if ($result2)
{
$_SESSION['player']=$player;


header("Location: index.php");
exit();
}
else
{
echo "<big>Wrong username or password.<A href='login.php'>Try Again</a></big>";
}
}
?>

Re: Successful login redirect

Posted: Sun Aug 16, 2009 2:14 pm
by hallsofvallhalla
try this

Code: Select all

<?php
include_once 'connect.php';
session_start();

header( 'refresh: 5; url=index.php' );

if (isset($_POST['submit']))
{
$player=$_POST['player'];
$password=$_POST['password'];
$player=strip_tags($player);
$password=strip_tags($password);
$password=md5($password);

$query = "select name,password from members where name='$player' and password = '$password'";
$result = mysql_query($query) or die("Could not query players");
$result2 = mysql_fetch_array($result);
if ($result2)
{
$_SESSION['player']=$player;
}
else
{
echo "<big>Wrong username or password.<A href='login.php'>Try Again</a></big>";
exit;
}
}
?>

Re: Successful login redirect

Posted: Sun Aug 16, 2009 7:19 pm
by Hutch
Thank you Halls

I had my header in the wrong location. The 5 second delay works well.

On a unsuccessful login I had to make a new page to redirect to, to let the player know the reason. I can deal with that.