Login PHP Problems
Posted: Sat Jan 20, 2007 9:22 am
I seem to be having big problems with my login page. I am able to authenticate a user, but when i try to redirect to another page i.e. mainsession.php nothing happens. I am trying to use
Is there away to reset data that is being held temporarily by the browser, as it keeps on going into the if statement if it has being previously ran in the last few minutes.
Heres my login page.
Code: Select all
header('Location: http://cs.tcd.ie/~kgleeso/arteface/mainsession.php');Heres my login page.
Code: Select all
<?php
session_start();
session_destroy();
$errorMessage = '';
if (isset($_POST['txtUserName']) && isset($_POST['txtPassword'])) {
include("db.inc.php");
mysql_connect($databaseServer,$user,$passwd) or die("Could not connect to the database.<br>".mysql_error());
mysql_select_db($database) or die("Could not select your database.<br>".mysql_error());
$username = $_POST['txtUserName'];
$password = $_POST['txtPassword'];
//echo $username;
//echo $password;
$sql = "SELECT userid, firstname, secondname
FROM user
WHERE username = '$username' AND password = '$password'";
//$query = "SELECT name, type, size, content FROM upload WHERE id = '$id'";
$result = mysql_query($sql) or die('Query failed. ' . mysql_error());
list($userid, $firstname, $secondname) = mysql_fetch_array($result);
//echo $userid;
//echo $firstname;
//echo $secondname;
//echo $username;
//echo $password;
if (($userid) >= 1) {
//print(We are in);
//$_SESSION['userid'] = true;
$_SESSION['userid'] = $userid;
print "Welcom, $_SESSION[userid]";
// header("Refresh: 10; url=http://cs.tcd.ie/~kgleeso/arteface/mainsession.php");
//header('Location: http://www.google.ie');
header('Location: http://cs.tcd.ie/~kgleeso/arteface/mainsession.php');
// exit;
} else {
$errorMessage = 'Sorry, wrong user id / password';
}
mysql_close();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php
if ($errorMessage != '') {
?>
<p align="center"><strong><font color="#990000"><?php echo $errorMessage; ?></font></strong></p>
<?php
}
?>
<form action="" method="post" name="frmLogin" id="frmLogin">
<table width="400" border="1" align="center" cellpadding="2" cellspacing="2">
<tr>
<td width="150">User Name</td>
<td><input name="txtUserName" type="text" id="txtUserName"></td>
</tr>
<tr>
<td width="150">PPPassword</td>
<td><input name="txtPassword" type="password" id="txtPassword"></td>
</tr>
<tr>
<td width="150"> </td>
<td><input name="btnLogin" type="submit" id="btnLogin" value="Login"></td>
</tr>
</table>
</form>
</body>
</html>