Successful login redirect

Post all your tuts or request for tuts here.
Post Reply
User avatar
Hutch
Posts: 95
Joined: Wed Aug 12, 2009 11:12 pm

Successful login redirect

Post 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>";
}
}
?>
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: Successful login redirect

Post 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;
}
}
?>
User avatar
Hutch
Posts: 95
Joined: Wed Aug 12, 2009 11:12 pm

Re: Successful login redirect

Post 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.
Post Reply

Return to “Tutorials”