Jump to content

login redirect


Saint48198

Recommended Posts

I have created a login page and I want to redirect the user if their login was successful. I've tried to use header but get an headers already sent error. I'm currently using meta tag but I don't like the delay or it does not work when  refresh is set to 0.

<?php

// database connect script.

require '../db_connect.php';

if($logged_in == 1) {
    
header( 'Location: http://www.agapefwc.org/test/admin/index.php' ) ;
}

?>
<?php $thisPage="Login"; ?>
<!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>Agape Christian Academy | <?php if ($thisPage!="") echo "$thisPage"; ?> Page</title>
<link rel="stylesheet" media="screen" type="text/css" href="../screen-sub.css" />
</head>

<body>
<div id="wrapper">
	<?php include("../includes/header.php"); ?>
	<div id="content" class="login">


		<?php

			if (isset($_POST['submit'])) { // if form has been submitted

				/* check they filled in what they were supposed to and authenticate */
				if(!$_POST['uname'] | !$_POST['passwd']) {
					die('You did not fill in a required field.');
				}

				// authenticate.

				if (!get_magic_quotes_gpc()) {
					$_POST['uname'] = addslashes($_POST['uname']);
				}

				$qry = "SELECT username, password FROM users WHERE username = '".$_POST['uname']."'";
				$check = $db_object->query($qry);

				if (DB::isError($check) || $check->numRows() == 0) {
					die('That username does not exist in our database.');
				}

				$info = $check->fetchRow();

				// check passwords match 

				$_POST['passwd'] = stripslashes($_POST['passwd']);
				$info['password'] = stripslashes($info['password']);
				$_POST['passwd'] = md5($_POST['passwd']);

				if ($_POST['passwd'] != $info['password']) {
					die('Incorrect password, please try again.');
				}

				// if we get here username and password are correct, 
				//register session variables and set last login time.

				$date = date('m d, Y');

				$qry = "UPDATE users SET last_login = '$date' WHERE username = '".$_POST['uname']."'";
				$update_login = $db_object->query($qry);

				$_POST['uname'] = stripslashes($_POST['uname']);
				$_SESSION['username'] = $_POST['uname'];
				$_SESSION['password'] = $_POST['passwd'];
				$db_object->disconnect(); 

			?>

			<meta http-equiv="refresh" content="1; URL=http://www.agapefwc.org/test/admin/index.php"; />

			<?php

			} else {    // if form hasn't been submitted

			?>
			<h1>Login</h1>
			<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
				<label for="uname">Username: </label>
				<input type="text" name="uname" maxlength="40">
				<br  />
				<label for="passwd">Password: </label>
				<input type="password" name="passwd" maxlength="50">
				<br />
				<input type="submit" name="submit" value="Login" class="btn">
			</form>
			<?php
			}
		?>
	</div>
	<?php include("../includes/footer.php"); ?>
</div>
</body>
</html>

???

Link to comment
https://forums.phpfreaks.com/topic/40785-login-redirect/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.