session errors.
Posted: Mon Jul 07, 2003 1:46 pm
I've written an application on one computer using php 4.3.1 (register globals turned off). Now I am using the app on a different computer using php 4.2.1 . (I havn't upgraded it because I have a address book app that will only work with register globals on. lotsa addresses!). In the header of my pages I have the following:
header.php
admin_session.php
basically the app is supposed to send the user to the login_form if they try to access a page directly without loging in, but instead I get the following errors:
Warning: Cannot send session cookie - headers already sent by (output started at C:\Program Files\Apache Group\Apache\projects\bookwriter\admin_session.php:2) in C:\Program Files\Apache Group\Apache\projects\bookwriter\admin_session.php on line 6
Warning: Cannot send session cache limiter - headers already sent (output started at C:\Program Files\Apache Group\Apache\projects\bookwriter\admin_session.php:2) in C:\Program Files\Apache Group\Apache\projects\bookwriter\admin_session.php on line 6
Warning: Cannot add header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache\projects\bookwriter\admin_session.php:2) in C:\Program Files\Apache Group\Apache\projects\bookwriter\admin_session.php on line 20
any clues?
header.php
Code: Select all
<?php
include("admin_session.php");
//connect to the database
$dbcnx = mysql_connect('localhost','username','password');
$bookconnect = mysql_select_db('bookwriter');
?>
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<title>Title here!</title>
<script language="Javascript1.2"><!-- // load htmlarea
_editor_url = "http://localhost/bookwriter/htmlarea/"; // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera') >= 0) { win_ie_ver = 0; }
if (win_ie_ver >= 5.5) {
document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
document.write(' language="Javascript1.2"></scr' + 'ipt>');
} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }
// --></script>
</head>
<body>
<div align="right"><a href="logout.php">logout</a></div>Code: Select all
<?php
//start the session
session_start();
//check to make sure the session variable is registered
if(isset($_SESSION['username'])){
//the session variable is registered, the user is allowed to see anything that follows
echo ("Logged in: " . "<strong>" . $_SESSION['username'] . "</strong>");
}
else{
//the session variable isn't registered, send them back to the login page
header( "Location: login_form.php" );
}
?>Warning: Cannot send session cookie - headers already sent by (output started at C:\Program Files\Apache Group\Apache\projects\bookwriter\admin_session.php:2) in C:\Program Files\Apache Group\Apache\projects\bookwriter\admin_session.php on line 6
Warning: Cannot send session cache limiter - headers already sent (output started at C:\Program Files\Apache Group\Apache\projects\bookwriter\admin_session.php:2) in C:\Program Files\Apache Group\Apache\projects\bookwriter\admin_session.php on line 6
Warning: Cannot add header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache\projects\bookwriter\admin_session.php:2) in C:\Program Files\Apache Group\Apache\projects\bookwriter\admin_session.php on line 20
any clues?