Jump to content

Header function doesn't appear to be working


metalhead41

Recommended Posts

Quick one this time...

On my test server running php 5.2.5 the function header('Location: main.php'); moves the user to the user area after they have logged in.

On a live server runnign php 4.4.8 it's not working, instead I have to reclick on the staff are link which then moves me to the correct area.

 

Any help would be appreciated  ???

Link to comment
Share on other sites

On another test server that is running php 5.2.2 it does the same thing. Looking at the logfiles I get this when logging in:

[23-Feb-2008 14:55:34] PHP Warning:  Cannot modify header information - headers already sent by (output started at C:\wamp\www\Websites\Erith\stafflogin.php:7) in C:\wamp\www\Websites\Erith\includes\login.php on line 24

 

This is the login.php script

<?php

$errorMessage = '';
if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) {
include 'library/config.php';
include 'library/opendb.php';

$userId   = $_POST['txtUserId'];
$password = $_POST['txtPassword'];

// check if the user id and password combination exist in database
$sql = "SELECT user_name,account_type FROM users WHERE user_name = '$userId' AND user_password = md5('$password')";
$result = mysql_query($sql) or die('Query failed. ' . mysql_error());

if (mysql_num_rows($result) == 1) {
	$row = mysql_fetch_assoc($result);
	// the user id and password match, 
	// set the session
	$_SESSION['username'] = $_POST['txtUserId'];
	$_SESSION['account_type'] = $row['account_type'];
	$_SESSION['db_is_logged_in'] = true;

	// after login we move to the main page
	header('Location: main.php');
	exit;
} else {
	$errorMessage = 'Sorry, wrong user id / password';
}

include 'library/closedb.php';
}

?>

<?php
if ($errorMessage != '') {
?>
<p align="center"><strong><font color="#990000"><?php echo $errorMessage; ?></font></strong></p>
<?php
}
?>
			<div id="login">
				<form action="" method="post" name="frmLogin" id="frmLogin">
					<label>User Name:</label>
					<input name="txtUserId" type="text" id="txtUserId" />
					<label>Password:</label>
					<input name="txtPassword" type="password" id="txtPassword" />
					<label> </label>
					<input name="btnLogin" type="submit" id="btnLogin" value="Login" />
				</form>
			</div>

 

This is main.php

 

<?php
// like i said, we must never forget to start the session
session_start();
include 'library/config.php';
    include 'library/opendb.php';
// is the one accessing this page logged in or not?
if (!isset($_SESSION['db_is_logged_in']) || $_SESSION['db_is_logged_in'] !== true) {
// not logged in, move to login page
header('Location: stafflogin.php');

include 'library/closedb.php';
exit;
}
    
$admin = "1";
$user = "2";
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

	<title>Erith Secondary School :: A Foundation School and a Specialist School in Sports Mathematics & Computing</title>

	<style type="text/css" media="all"> @import "./scripts/main.css"; </style>
	<script type="text/javascript">			
		function delArticle(id, name)
		{
			if (confirm("Are you sure you want to delete '" + name + "'"))
			{
				window.location.href = 'main.php?del=' + id;
			}
		}
	</script>

</head>
<body>
	<div id="sitewrap">
		<?php include'includes/header.php';?>
		<?php include'includes/menu.php';?>

		<div id="contents">
			<?php include'includes/date.php'?>
			<p>Welcome <?php echo $_SESSION['username'];?> how are you today?</p>
			<p><a href="./includes/logout.php">Click here to Logout</a></p>

			<div id="download">
				<?php
				if($_SESSION['account_type'] == $admin){
					echo "You can use this to upload and download new memo's or bulletins.";?><br />
				<?php echo "Please only upload word files or PDF's. Make sure your files are labled appropriatley.";
					include 'includes/admin.php';
					}
				if($_SESSION['account_type'] == $user){
					echo "<p>Use these links to download the latest bulletin and memo.</p>";
					include 'includes/user.php';
					}
				?>
			</div>
			<p><a href="./includes/logout.php">Click here to Logout</a></p>
		</div>
		<?php include'includes/footer.php';?>
	</div>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.